DISTINCTCOUNT function resulting in unwanted aggregation; how to fix it - dax

I have a list of shopping centers that are marked by different age groups with calculated age for the next 10 years.
I am using a rotating card visual that will respond to the year slicer, and I would like the DISTINCTCOUNT function output is set to default to the first year (if I set it to first year using filter, the visual will display Blank for any other years).
Table:
Center Year Age Age Grouping
A 2023 0 0-5
A 2024 1 0-5
A 2025 2 0-5
A 2026 3 0-5
A 2027 4 0-5
A 2028 5 0-5
A 2029 6 06-10
A 2030 7 06-10
A 2031 8 06-10
A 2032 9 06-10
A 2033 10 06-10
B 2023 1 0-5
B 2024 2 0-5
B 2025 3 0-5
B 2026 4 0-5
B 2027 5 0-5
B 2028 6 06-10
B 2029 7 06-10
B 2030 8 06-10
B 2031 9 06-10
B 2032 10 06-10
B 2033 11 11-15
The DAX I wrote for calculated measures are:
Total Center = DISTINCTCOUNT(Center[Center])
Centers 0-5 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "0-5")
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "06-10")
I did not list all data points here because the list goes on and they follow the same pattern. I used DISTINCTCOUNT for all measures but for some reasons, only calculated measure [Total Center] and [Centers 0-5 Years Old] showed up correctly without aggregation; the rest of the measures (e.g. [Centers 6-10 Years Old]) showed up aggregated for all 10 years by default. I attached an image of the metrics below:
This is effecting my rotating card visual that by default it shows Total Center as 211, Centers 0-5 Years Old as 114, Centers 6-10 Years Old as 150 (aggregated), and rest are all aggregated.
I don't know why they are displaying differently when the DAX I used are all the same. There is no filter set on visuals or on the table.
Any advice will be much appreciated.
I have tried changing it from
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),Center[Age Grouping] = "06-10")
to
Centers 6-10 Years Old = CALCULATE(DISTINCTCOUNT(Center[Center]),FILTER(Center,Center[Age Grouping] = "06-10"))
but nothing have changed.

Related

PowerBI compare two columns in matrix

I am pretty new to PowerBI and cannot figure out a way to compare two values in two columns. All I need is a columns that says True or False. This would be pretty easy in Excel but I am sure there is a way in PowerBI as well?
My data looks like this:
Number
Type
Size
PO1
5
10
PO1
6
12
PO2
5
09
PO2
6
10
PO3
5
10
PO3
6
10
Which I organise to look like this in a matrix (not exactly this formatting but I don't know how to show this, but it's a matrix):
Number
Type 5
Size
Type 6
Size
PO1
5
10
6
12
PO2
5
09
6
10
PO3
5
10
6
10
And I want to know:
Number
Type 5
Size
Type 6
Size
Same size
PO1
5
10
6
12
False
PO2
5
09
6
10
False
PO3
5
10
6
10
True
You could solve this with a calculated table like:
Comparison =
SUMMARIZE(
'Table',
'Table'[Number],
"Same size", MIN('Table'[Size]) = MAX('Table'[Size])
)
which will look like this in a table visual:
What I did was Transform the data as follows:
Number as index column
Min size as 'input'
Max size as 'output'
New column comparing input and output
Save and Run

TiBCO Spotfire - How to Calculate only the last 3 columns in a Data - see descr

Week Sales
1 100
2 250
3 350
4 145
5 987
6 26
7 32
8 156
I wanted to calculate the sales only for the last 3 weeks so the total will be 156+32+26.
If new weeks are added it should automatically calculate only the data from the last 3 rows.
Tried this formula but it is returning an incorrect sum
sum(sales) over (lastperiod(3(week))
https://i.stack.imgur.com/6Y7h7.jpg
If you want only the last 3 weeks sum in calculated column you can use a simple if calculation.
If([week]>(Max([week]) - 3),Sum([sales]),0)
If you need 3 weeks calculation throughout table use below one.
sum([sales]) OVER (LastPeriods(3,[week]))

gnuplot time axis from two different columns

I'm trying to plot some data from a four columns file. The first one is the numbre of data the second one is the year the third one are months and the final one are values of temperature. The thing is that I woul like that my x axis takes a date from the second and the third columns.
The text file look like this:
1 1990 2 265.78945923
2 1990 3 260.53842163
3 1990 4 265.00366211
4 1990 5 277.61206055
5 1990 6 284.72595215
6 1990 7 291.54879761
7 1990 8 293.61392212
8 1990 9 288.47149658
9 1990 10 284.55172729
12 1991 1 285.98762388
13 1991 2 283.47484293
I'm using a code like this:
set xdata time
set timefmt '%Y %m'
plot 'datafile' u 2:4
But it doesn't work. I woul like to have on my x axis the year and the months.
All help appreciated! Thanks

Pair items from array in unique groups

I have an array of numbers ([1,2,3,4,5,6,7,8,9,10]). These numbers represent players. I would like these players to each "play" each other exactly once.
I need to create "Rounds" for these games. These rounds will include a even number of matches, and each player can only play in a round, at most, once. If there's an odd number of matches, than a final round with irregular number of matches is okay.
The end result being an array of "Round" arrays. These round arrays will contain the matches between players. The end result being something like below, but complete:
[[[1,2],[3,4],[5,6],[7,8],[9,10]],[[1,3],[2,4],[5,7],[6,8],[9,1],[10,2]]]
I've found Array#combination for getting the matches created, but I can't seem to get the rounds to build properly.
That is called a round robin tournament. Wikipedia gives the following algorithm
Round 1. (1 plays 14, 2 plays 13, ... )
1 2 3 4 5 6 7
14 13 12 11 10 9 8
then fix one competitor (number one in this example) and rotate the others clockwise one position:
Round 2. (1 plays 13, 14 plays 12, ... )
1 14 2 3 4 5 6
13 12 11 10 9 8 7
And keep rotating:
Round 3. (1 plays 12, 13 plays 11, ... )
1 13 14 2 3 4 5
12 11 10 9 8 7 6
An odd number of players is handled by one player per round having no game (often implemented by adding a dummy player).

Sum Pyramid with backtracking

I'm trying to solve this problem and I'm new to backtracking algorithms,
The problem is about making a pyramid like this so that a number sitting on two numbers is the sum of them. Every number in the pyramid has to be different and less than 100. Like this:
88
39 49
15 24 25
4 11 13 12
1 3 8 5 7
Any pointers on how to do this using backtracking?
Not necessarily backtracking but the property you are asking for is interestingly very similar to the Pascal Triangle property.
The Pascal Triangle (http://en.wikipedia.org/wiki/Pascal's_triangle), which is used for efficient computation of binomial coefficient among other things, is a pyramid where a number is equal to the sum of the two numbers above it with the top being 1.
As you can see you are asking the opposite property where a number is the sum of the numbers below it.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
For instance in the Pascal Triangle above, if you wanted the top of your pyramid to be 56, your pyramid will be a reconstruction bottom up of the Pascal Triangle starting from 56 and that will give something like:
56
21 35
6 15 20
1 5 10 10
Again that's not a backtracking solution and this might not give you a good enough solution for every single N though I thought this was an interesting approximation that was worth noting.

Resources