Powerpivot 2016 measure using DAX to sum an array - arrays

I want to sum the 7 preceding values of a row as a measure like so:
| Wk_number | Value A | Measure | Array |
-------------------------------------------
| 01 | 1 | N/A# | N/A# |
| 02 | 1 | 1 | {01} |
| 03 | 10 | 2 | {01-02} |
| 04 | 3 | 12 | {01-03} |
| 05 | 5 | 15 | {01-04} |
| 06 | 10 | 20 | {01-05} |
| 07 | 1 | 30 | {01-06} |
| 08 | 4 | 31 | {01-07} |
| 09 | -10 | 34 | {02-08} |
| 10 | 3 | 26 | {03-09} |
| 11 | 2 | 18 | {04-10} |
etc...
I added the array column just to clarify the example how of the sum is comprised, notice that from wk09 it's not simply a running total.
How to do this using DAX statements?

Two ways to do this: you can either create a calculated column, or a measure.
For the column:
=CALCULATE(SUM([Value A]),FILTER(Table,Table[Wk_number]<EARLIER(Table[Wk_number]) && Table[Wk_number] >= (EARLIER(Table[Wk_number])-7)))
For the measure, it's a very similar formula but instead of using EARLIER(), we use MAX():
=CALCULATE(SUM([Value A]),FILTER(ALL(Table3),Table3[Wk_number]<MAX(Table3[Wk_number]) && Table3[Wk_number] >= (MAX(Table3[Wk_number])-7)))
Below is a screenshot of the results. A few of the numbers in your example table seem to be off based on the math:

Related

group first started date and last end date for records with a common field

Here is an excerpt of my table data:
|deviceid | |failcount| started | ended |
| a1078 | | 2 | 2020-12-07 14:51:33 | 2020-12-07 17:30:16|
|a1006 | | 2 | 2020-12-09 15:58:01 | 2020-12-09 23:59:59|
|a1006 | | 2 | 2020-12-10 00:00:00 | 2020-12-10 16:40:02|
|a136 | | 71 | 2020-12-18 10:12:19 | 2020-12-18 23:59:59|
|a136 | | 71 | 2020-12-19 00:00:00 | 2020-12-19 04:27:23|
|a1078 | | 36 | 2020-12-21 10:07:09 | 2020-12-21 14:36:40|
What I am trying to get to is to get the earliest start date and the latest end date for each deviceid, BUT for only the same failcount number. The failcount number is the # of failures for each deviceid, so multiple deviceid's can have the same failcount number (should be very few).
This is what im trying to get to:
|deviceid| |failcount| | started | | ended |
|a1078 | | 2 | | 2020-12-07 14:51:33 | |2020-12-07 17:30:16|
|a1006 | | 2 | |2020-12-09 15:58:01 | |2020-12-10 16:40:02|
|a136 | | 71 | |2020-12-18 10:12:19 | |2020-12-19 04:27:23|
|a1078 | | 36 | | 2020-12-21 10:07:09 | |2020-12-21 14:36:40|
I've tried variations of min/max but can't figure out how to keep different failcounts from same deviceid from being combined - for instance, in the above for deviceid a1078, I don't want the started for failcount 2 and the ended for failcount 36.
What I have so far is this but it is combining different failcounts for the same deviceid:
select deviceid
, min(started) as started
, max(started) as ended
from dayfail
where eventno = '600509'
and Convert(char(6),started, 112) = '202012'
group by deviceid
Thx in advance for any assistance to this sql newbie ;)

Windows 10 all icon resolutions on all DPI settings? Format? Pixel art as icon? Large size icon in start menu medium tile?

Just skip to the answer at the answer section, the question part has speculations and mistakes. The answer is based on experiment and it is accurate.
For a long time I have used a single png packed 256px ico file for my Visual Studio projects, and it worked well, cause scaling works fine on those icons and they take almost no space, and I did not care that much before.
But now I have an icon that needs to "retain hard edges", it is "pixel art".
If I build with a 256px version downscales terribly or if I build with 16px upscales slightly less terribly but not good enough. So my questions are:
What are the sizes I have to generate to merge into the ico (I don't care about pre win7 icons)?
If I got that list, do I have to generate 1.25x, 1.5x and 2.0x versions for high dpi settings?
Finally, some apps like firefox has a large icon on start menu inside the medium square block, my apps have a smaller one in the center like Visual Studio does, how can I put a large icon in the start menu medium sized square?
I did found it: Unfortunately VS says: VisualElements is not supported in a Windows Presentation Foundation (WPF) project. Is there a way around this?
I looked around and collected possible sizes #1x(96DPI):
16, 20, 24, 30, 32, 40, 48, 50, 64, 128, 150, 256, 512, 768
Mostly I collected these from Which icon sizes should my Windows application's icon include?.
Not that bad, but if I add 1.25x, 1.5x, 2.0x then we get:
16, 20, 24, 25, 30, 32, 36, 38, 40, 45, 48, 50, 60, 62, 64, 72, 75, 80, 96, 100, 128, 150, 160, 188, 192, 225, 256, 300, 320, 384, 512, 640, 768, 960, 1024, 1152, 1536 In my case it makes a 500k ico file and as it seems the 1024 is the max resolution you can put into an ico file, my icon is pixelated so compresses really well with png and still ~500k.
I also made an ico has all of the above resolutions in rgba, and every one has its size on it, so you can see which windows loads on which dpi setting. you can download it from here and use it in a vs project to test.
As I understand everything under 256px can't be png compressed, is this right?
And do I need all these sizes to retain a pixel perfect icon? Are only 32bit(RGBA) pngs okay? I hope I don't need to include other depths.
After i wrote an ico writer from the spec I realized that pngs can have 0 for resolution cause 1 byte is available for x or y(but i have never seen an ico that is non square, maybe curs can be non square), in this case probably the first one in the file with zeros for resolution going to be used...This is not sure but I think its not far from the truth. See images. Rescaling issues are still confusing me, if I'll have some time tomorrow I'll test it. A pixel perfect icon seems to be imposible to do: having one image to rescale to anything above 256px.
The answers:
Are PNGs are acceptable under 256px inside ICO file?
Microsoft states that the sizes under 256px should be a BMP without the first 14 bytes.
But at least in the case of windows 10, the answer is YES.
Can you add larger than 1024px image into the ICO?
YES. As long as it is a PNG it can be as big as you want.
Note the "one icon over 255px" limitation:
You can only add one image larger than 255px ( you can add more but windows will only read the first image block in the ICO head where the resolution is 0,0). The format specifies 1 byte for each dimension. See table #2.
What sizes to include for all DPI setting?
Windows 10 uses the following icon sizes (see table below):
16, 20, 24, 28, 30, 31, 32, 40, 42, 47, 48, 56, 60, 63, 84 and one larger than 255px.
Note that Windows RT apps do not use ICO files, they use PNGs or Fonts, this is from Firefox's source:
<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<VisualElements
ShowNameOnSquare150x150Logo='on'
Square150x150Logo='browser\VisualElements\VisualElements_150.png'
Square70x70Logo='browser\VisualElements\VisualElements_70.png'
ForegroundText='light'
BackgroundColor='#0996f8'/>
</Application>
So how Firefox has a large icon on start menu in the medium tile?
Well its include this above file in the exe directory before the shortcut added to start menu, this article explains it how. My app has an example.
If you make icons for Windows 10 you are better off with my tool and photoshop (or something like that) than anything else, I tried editors and they suck.
win10iconTools by me
You can create ICO files (as MS recommendation or not) or create icons with resolution printed on them, the latter is what I used to make the table.
Supports multiple resize modes including nearest neighbor.
If you want to you can use it on other windows versions, it works with .net2, test another windows, send me the results and I extend the table for the good of mankind.
As for pixel art in icons it is not possible to be perfect :(, unless we can change the scaling algorithm in windows 10.
So a wide range 84-256 gets the scaled to "0" (see above), so there is no real point adding something bigger that 256 as I see it now you should create a 256px image for "0".
(See table why)
If Windows gets all icons 16 to 255 + the 1 larger than 255 (0 in the table) chooses these sizes:
(so no markdown tables here?, its kind of wide, the tables are in the app readme also)
| | Windows 10 |
| | 96DPI | 120DPI | 144DPI | 168DPI |
| icon |disp.|load|disp.|load|disp.|load|disp.|load|
|-------------------------------------------|-----|----|-----|----|-----|----|-----|----|
| alt-tab | 24 | 32 | 30 | 32 | 36 | 32 | 42 | 32 |
| desktop large | 96 | 0 | 120 | 0 | 144 | 0 | 168 | 0 |
| desktop medium | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| desktop small | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 56 |
| explorer content, inc0 | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 56 |
| explorer extra large | 256 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| explorer large | 96 | 0 | 120 | 0 | 144 | 0 | 168 | 0 |
| explorer medium | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| explorer small:inc4,list:inc3,details:inc2| 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| explorer tiles, inc1 | 48 | 48 | 60 | 60 | 72 | 72 | 84 | 84 |
| startmenu medium | 32 | 32 | 40 | 40 | 48 | 48 | 56 | 63 |
| startmenu programs | 24 | 24 | 30 | 30 | 36 | 36 | 42 | 42 |
| startmenu search | 32 | 60 | 40 | 60 | 48 | 60 | 56 | 0 |
| startmenu tile small | 24 | 24 | 30 | 31 | 36 | 39 | 42 | 47 |
| taskbar normal | 24 | 32 | 30 | 40 | 36 | 48 | 42 | 56 |
| taskbar small | 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| window icon | 16 | 16 | 20 | 16 | 24 | 16 | 28 | 16 |
| desktop inc0 | 16 | 16 | 20 | 20 | 24 | 24 | 28 | 28 |
| desktop inc1 | 18 | 32 | 23 | 40 | 27 | 48 | 32 | 56 |
| desktop inc2 | 20 | 30 | 25 | 40 | 30 | 48 | 35 | 56 |
| desktop inc3 | 22 | 32 | 28 | 40 | 33 | 48 | 39 | 56 |
| desktop inc4 | 24 | 32 | 30 | 40 | 36 | 48 | 42 | 56 |
| desktop inc5 | 27 | 32 | 34 | 40 | 41 | 48 | 47 | 56 |
| desktop inc6 | 30 | 32 | 38 | 40 | 45 | 48 | 53 | 56 |
| desktop inc7 | 33 | 48 | 41 | 60 | 50 | 72 | 58 | 84 |
| desktop inc8 | 37 | 48 | 46 | 60 | 56 | 72 | 65 | 84 |
| desktop inc9 | 41 | 48 | 51 | 60 | 62 | 72 | 72 | 84 |
| desktop inc10 | 46 | 48 | 58 | 60 | 69 | 72 | 82 | 84 |
| desktop inc11 | 51 | 0 | 64 | 0 | 77 | 0 | 89 | 0 |
| desktop inc12 | 57 | 0 | 71 | 0 | 86 | 0 | 100 | 0 |
| desktop inc13 | 63 | 0 | 79 | 0 | 95 | 0 | 110 | 0 |
| desktop inc14 | 70 | 0 | 88 | 0 | 105 | 0 | 123 | 0 |
| desktop inc15 | 78 | 0 | 98 | 0 | 117 | 0 | 137 | 0 |
| desktop inc16 | 87 | 0 | 109 | 0 | 131 | 0 | 152 | 0 |
| desktop inc17 | 97 | 0 | 121 | 0 | 146 | 0 | 170 | 0 |
| desktop inc18 | 108 | 0 | 135 | 0 | 162 | 0 | 189 | 0 |
| desktop inc19 | 120 | 0 | 150 | 0 | 180 | 0 | 210 | 0 |
| desktop inc20 | 133 | 0 | 166 | 0 | 200 | 0 | 233 | 0 |
| desktop inc21 | 148 | 0 | 185 | 0 | 222 | 0 | 256 | 0 |
| desktop inc22 | 164 | 0 | 205 | 0 | 246 | 0 | 256 | 0 |
| desktop inc23 | 182 | 0 | 228 | 0 | 256 | 0 | 256 | 0 |
| desktop inc24 | 202 | 0 | 253 | 0 | 256 | 0 | 256 | 0 |
| desktop inc25 | 224 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| desktop inc26 | 249 | 0 | 256 | 0 | 256 | 0 | 256 | 0 |
| explorer inc5 | 18 | 32 | 23 | | | | | |
| explorer inc6 | 20 | 32 | 25 | | | | | |
| explorer inc7 | 22 | 32 | 28 | | | | | |
| explorer inc8 | 23 | 32 | 29 | | | | | |
| explorer inc9 | 25 | 32 | 31 | | | | | |
| explorer inc10 | 27 | 32 | 34 | | | | | |
| explorer inc11 | 29 | 32 | 36 | | | | | |
| explorer inc12 | 31 | 32 | 39 | | | | | |
| explorer inc13 | 33 | 48 | 41 | | | | | |
| explorer inc14 | 35 | 48 | 44 | | | | | |
| explorer inc15 | 38 | 48 | 48 | | | | | |
| explorer inc16 | 41 | 48 | 51 | | | | | |
| explorer inc17 | 44 | 48 | 55 | | | | | |
| explorer inc18 | 47 | 48 | 59 | | | | | |
| explorer inc19 | 50 | 0 | 63 | | | | | |
| explorer inc20 | 54 | 0 | 68 | | | | | |
| explorer inc44 | 239 | 0 | 256 | 0 | | | | |
| explorer inc45 | 256 | 0 | 256 | 0 | | | | |
There are 27 zoom increments on desktop
and 45 zoom increments on explorer (including the defaults from the menu on the "bottom level")
Icon format specification:
|**block** |**offset** |**offset** |**length** |**description** |
|-----------|-----------|-----------|-----------|-------------------------------|
|main header| 0 | | 2 |Reserved=0 |
| | 2 | | 2 |Image type: 1(.ICO) 2(.CUR) |
| | 4 | | 2 |Number of images in container |
|image head1| 6 | 0 | 1 |Pixel width |
| | 7 | 1 | 1 |Pixel height |
| | 8 | 2 | 1 |Color palette size or 0 |
| | 9 | 3 | 1 |Reserved=0 |
| | A | 4 | 2 |Color planes=0 or 1 |
| | C | 6 | 2 |Bits per Pixel |
| | E | 8 | 4 |Image raw size |
| | 12 | C | 4 |Offset of imageblock from BOF |
|image head2| 16 | 0 | 1 |Pixel width |
| ... | ... | ... | ... |... |
|imageblock1| ... | ... | ... |all image data goes here: |
| | ... | ... | ... | pngs included in whole |
| | ... | ... | ... | bmps missing first 14 bytes |
The icons you see in Windows 10 are packed into a icon font named Segoe MDL2 Assets & all built-in UWP apps like Groove Music are using this font for icons. Also some apps in the Windows store using it.

SQL Database Constraint | Multi-table Constraint

I need to make 2 database constraints that connect two different tables at one time.
1. The total score of the four quarters equals the total score of the game the quarters belong to.
2. The total point of all the players equals to the score of the game of that team.
Here is what my tables look like.
quarter table
+------+--------+--------+--------+
| gNum | Period | hScore | aScore |
+------+--------+--------+--------+
| 1 | 1 | 13 | 18 |
| 1 | 2 | 12 | 19 |
| 1 | 3 | 23 | 31 |
| 1 | 4 | 32 | 18 |
| | | Total | Total |
| | | 80 | 86 |
+------+--------+--------+--------+
Game Table
+-----+--------+--------+--------+
| gID | hScore | lScore | tScore |
+-----+--------+--------+--------+
| 1 | 86 | 80 | 166 |
+-----+--------+--------+--------+
Player Table
+-----+------+--------+--------+
| pID | gNum | Period | Points |
+-----+------+--------+--------+
| 1 | 1 | 1 | 20 |
| | | 2 | 20 |
| | | 3 | 20 |
| | | 4 | 20 |
+-----+------+--------+--------+
So Virtually I need to use CHECK I think to make sure that players points = score of their team ie (hScore, aScore) and also make sure that the hScore and aScore = the total score in the Game table.
I was thinking of creating a foreign key variable on one of the tables and setting up constraints on that would this be the best way of going about it?
Thanks

Working Through Normalization (3NF)

I've been planning this website for a while now and began putting it together a few weeks ago and I'd say that things were going extremely well until the other day I was introduced to normalization. It's taken me quite some time to get the hang of what it is and why it's needed but I think that I'm close to acheiving my overall goal now.
So the scenario is that I have a website where members can join and set up their own newspaper/blog and assign authors to it. The site primarily consists of a members_table, authors_table, newspapers_table and posts_table, which I've gone through and normalized to get:
Members
+----+-----------+----------+-----------------+----------+----------+------------+------------+
| ID | FIRSTNAME | SURNAME | EMAIL | USERNAME | PASSWORD | AVATAR | JOINED |
+----+-----------+----------+-----------------+----------+----------+------------+------------+
| 01 | Brian | Griffin | brian#gmail.com | briang | *** | hdhs.jpg | 2014-07-31 |
| 02 | Meg | Griffin | meg#gmail.com | megg | *** | | 2014-07-31 |
| 03 | Peter | Griffin | peter#gmail.com | peterg | *** | jaunsq.jpg | 2014-07-31 |
| 04 | Glen | Quagmire | glen#gmail.com | glen | *** | | 2014-07-31 |
+----+-----------+----------+-----------------+----------+----------+------------+------------+
Authors
+----+-----------+----------+-----------------+-------------------+---------+----------+---------+
| ID | FIRSTNAME | SURNAME | EMAIL | BIO ( REQUIRED ) | TWITTER | FACEBOOK | WEBSITE |
+----+-----------+----------+-----------------+-------------------+---------+----------+---------+
| 01 | Brian | Griffin | brian#gmail.com | About me... | URL | | URL |
| 02 | Meg | Griffin | meg#gmail.com | About me... | URL | | |
| 03 | Peter | Griffin | peter#gmail.com | About me... | | URL | URL |
| 04 | Glen | Quagmire | glen#gmail.com | About me... | URL | URL | |
+----+-----------+----------+-----------------+-------------------+---------+----------+---------+
** Should Socials Be Broken Down Here? If So, How?
Newspaper_Categories
+----+-------------------+
| ID | CATEGORY |
+----+-------------------+
| 01 | Lifestyle |
| 02 | Auto Mobiles |
| 03 | Entertainment |
| 04 | Food & Drink |
| 05 | Internet |
+----+-------------------+
Newspapers
+----+-----------------------+----------+---------+------------------+------------------+
| ID | NAME | CATEGORY | AVATAR | BIO ( REQUIRED ) | OWNER ( MEMBER ) |
+----+-----------------------+----------+---------+------------------+------------------+
| 01 | Spooner Street Weekly | 01 | 311.jpg | About Us... | 01 |
| 02 | A Dogs Life | 01 | | About Us... | 01 |
| 03 | In The Kitchen | 04 | js.jpg | About Us... | 02 |
+----+-----------------------+----------+---------+------------------+------------------+
Should Owner go Here or in a table named Newspaper_Owners
Socials
+----+-------------------+
| ID | TYPE |
+----+-------------------+
| 01 | Facebook |
| 02 | Twitter |
| 03 | Google |
| 04 | Flickr |
| 05 | Youtube |
+----+-------------------+
Newspaper_Socials
+----------+--------+------+
| NEWSAPER | SOCIAL | LINK |
+----------+--------+------+
| 01 | 01 | URL |
| 01 | 02 | URL |
| 01 | 05 | URL |
| 01 | 01 | URL |
| 02 | 02 | URL |
| 02 | 04 | URL |
| 03 | 01 | URL |
+----------+--------+------+
Post_Categories
+-------------------+--------------------+
| ID | NEWSPAPER_ID | CATEGORY |
+----+--------------+--------------------+
| 01 | 01 | Glens Girls |
| 02 | 01 | In The Clam |
| 03 | 01 | Peters Shenanigans |
| 04 | 02 | Martini Recipes |
| 05 | 03 | Housewife Tips |
+----+--------------+--------------------+
Posts
+----+----------+-------+---------+----------+------------+-------+
| ID | CATEGORY | TITLE | ARTICLE | FEATURED | ADDED | VIEWS |
+----+----------+-------+---------+----------+------------+-------+
| 01 | 01 | Title | Article | 0 | 2014-07-31 | 200 |
| 02 | 01 | Title | Article | 0 | 2014-07-31 | 220 |
| 03 | 03 | Title | Article | 1 | 2014-07-31 | 232 |
| 04 | 05 | Title | Article | 0 | 2014-07-31 | 143 |
| 05 | 05 | Title | Article | 1 | 2014-07-31 | 311 |
+----+----------+-------+---------+----------+------------+-------+
Post_Photos
+---------+-----+--------------+------+
| POST_ID | ALT | PHOTOGRAPHER | LINK |
+---------+-----+--------------+------+
| 01 | Alt | John Smith | URL |
| 02 | Alt | | |
| 03 | Alt | Mike Jones | |
| 05 | Alt | Adam West | URL |
+---------+-----+--------------+------+
Post_Keywords
+---------+---------+
| POST_ID | KEYWORD |
+---------+---------+
| 01 | Keyword |
| 01 | Keyword |
| 01 | Keyword |
| 01 | Keyword |
| 02 | Keyword |
| 02 | Keyword |
| 03 | Keyword |
| 03 | Keyword |
| 03 | Keyword |
+---------+---------+
If each post is only allowed 3 keywords, can these be added to the end of Posts table?
Author_Posts
+-----------+---------+
| AUTHOR_ID | POST_ID |
+-----------+---------+
| 01 | 01 |
| 01 | 02 |
| 01 | 03 |
| 02 | 04 |
| 03 | 05 |
+-----------+---------+
Could anyone please let me know if I'm on the right lines with this structure and give me some pointers on where Primary Keys and also Foreign Keys ??? should go?
"** Should Socials Be Broken Down Here? If So, How?"
Yes, you already have the socials table.
Add a new many to many table of Users to Socials

Transform ranged data in an Access table

I have a table in Access database as below;
Name | Range | X | Y | Z
------------------------------
A | 100-200 | 1 | 2 | 3
A | 200-300 | 4 | 5 | 6
B | 100-200 | 10 | 11 | 12
B | 200-300 | 13 | 14 | 15
C | 200-300 | 16 | 17 | 18
C | 300-400 | 19 | 20 | 21
I have trying write a query that convert this into the following format.
Name | X_100_200 | Y_100_200 | Z_100_200 | X_200_300 | Y_200_300 | Z_200_300 | X_300_400 | Y_300_400 | Z_300_400
A | 1 | 2 | 3 | 4 | 5 | 6 | | |
B | 10 | 11 | 12 | 13 | 14 | 15 | | |
C | | | | 16 | 17 | 18 | 19 | 20 | 21
After trying for a while the best method I could come-up with is to write bunch of short queries that selects the data for each Range and then put them together again using a Union query. The problem is that for this example I have shown 3 columns (X, Y and Z), but I actually have much more. Access is starting to strain with the amount of SQL I have come up with.
Is there a better way to achieve this?
The answer was simple. Just use Access Pivotview. Finding it hard to export the results to Excel though.

Resources