Forum Discussion
DAX
- 6 years ago
Hi Sujit_Thakur ,
Do you want to count the number of Model or the number of Name?
We can create two measures and use the following ways to meet your requirement.
1. Create a Model column in data table.
Model = CALCULATE(MAX('index table'[Model]),FILTER('index table','index table'[Name]='data table'[Name]))2. Create a new table.
Table = CROSSJOIN(VALUES('index table'[Model]),{"<0.25","0.25-0.5","0.5-0.75",">0.75","Total"})3. If you want to count the number of Name, you can use the following measure.
Measure = var _025 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]<0.25 && 'data table'[Model]=MAX('Table'[Model]))) var _025_05 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.25&&[Test]<0.5 && 'data table'[Model]=MAX('Table'[Model]))) var _05_075 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.5&&[Test]<0.75 && 'data table'[Model]=MAX('Table'[Model]))) var _075 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.75&& 'data table'[Model]=MAX('Table'[Model]))) return SWITCH( TRUE(), MAX('Table'[Value]) = "<0.25",_025, MAX('Table'[Value]) = "0.25-0.5",_025_05, MAX('Table'[Value]) = "0.5-0.75",_05_075, MAX('Table'[Value]) = ">0.75",_075, MAX('Table'[Value]) = "Total",_025+_025_05+_05_075+_075)4. If you want to count the number of Model, you can use the following measure.
Measure 2 = var _025 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]<0.25 && 'data table'[Model]=MAX('Table'[Model]))) var _025_05 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.25&&[Test]<0.5 && 'data table'[Model]=MAX('Table'[Model]))) var _05_075 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.5&&[Test]<0.75 && 'data table'[Model]=MAX('Table'[Model]))) var _075 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.75&& 'data table'[Model]=MAX('Table'[Model]))) return SWITCH( TRUE(), MAX('Table'[Value]) = "<0.25",_025, MAX('Table'[Value]) = "0.25-0.5",_025_05, MAX('Table'[Value]) = "0.5-0.75",_05_075, MAX('Table'[Value]) = ">0.75",_075, MAX('Table'[Value]) = "Total",_025+_025_05+_05_075+_075)The SWITCH function means that when the current column is equal to a certain value, output the corresponding value.
For example, when Table[Value] = “<0.25”, then output the value conforming to <0.25.
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
Dear v-zhenbw-msft ,
following is my data
1)First table is index table
| Id | Name | Model |
| 1 | A | Alpha |
| 2 | B | Alpha |
| 3 | C | Bravo |
| 4 | D | Bravo |
| 5 | E | Charlie |
2)Second is data table
| Date | Name | HP | OP |
| 7/1/2020 | A | 23 | 22 |
| 7/2/2020 | A | 20 | 19 |
| 7/3/2020 | A | 20 | 29 |
| 7/4/2020 | A | 22 | 40 |
| 7/5/2020 | A | 21 | 100 |
| 7/1/2020 | B | 22 | 50 |
| 7/2/2020 | B | 21 | 50 |
| 7/3/2020 | B | 23 | 100 |
| 7/4/2020 | B | 22 | 23 |
| 7/5/2020 | B | 20 | 17 |
| 7/1/2020 | C | 23 | 20 |
| 7/2/2020 | C | 21 | 17 |
| 7/3/2020 | C | 22 | 15 |
| 7/4/2020 | C | 21 | 14 |
| 7/5/2020 | C | 23 | 12 |
| 7/1/2020 | D | 21 | 100 |
| 7/2/2020 | D | 22 | 50 |
| 7/3/2020 | D | 21 | 50 |
| 7/4/2020 | D | 23 | 100 |
| 7/5/2020 | D | 22 | 23 |
| 7/1/2020 | E | 20 | 17 |
| 7/2/2020 | E | 23 | 20 |
| 7/3/2020 | E | 23 | 17 |
| 7/4/2020 | E | 23 | 50 |
| 7/5/2020 | E | 23 | 100 |
Now what i want as an output is
Model Total Count <0.25 0.25-0.50 0.50-0.75 >0.75
Alpha 2 2
Bravo 2 1 1
Charlie 1 1
please also explain your code of switch function i didnt understood
- v-zhenbw-msft6 years agoCommunity Support
Hi Sujit_Thakur ,
Do you want to count the number of Model or the number of Name?
We can create two measures and use the following ways to meet your requirement.
1. Create a Model column in data table.
Model = CALCULATE(MAX('index table'[Model]),FILTER('index table','index table'[Name]='data table'[Name]))2. Create a new table.
Table = CROSSJOIN(VALUES('index table'[Model]),{"<0.25","0.25-0.5","0.5-0.75",">0.75","Total"})3. If you want to count the number of Name, you can use the following measure.
Measure = var _025 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]<0.25 && 'data table'[Model]=MAX('Table'[Model]))) var _025_05 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.25&&[Test]<0.5 && 'data table'[Model]=MAX('Table'[Model]))) var _05_075 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.5&&[Test]<0.75 && 'data table'[Model]=MAX('Table'[Model]))) var _075 = CALCULATE(COUNT('data table'[Name]),FILTER('data table',[Test]>=0.75&& 'data table'[Model]=MAX('Table'[Model]))) return SWITCH( TRUE(), MAX('Table'[Value]) = "<0.25",_025, MAX('Table'[Value]) = "0.25-0.5",_025_05, MAX('Table'[Value]) = "0.5-0.75",_05_075, MAX('Table'[Value]) = ">0.75",_075, MAX('Table'[Value]) = "Total",_025+_025_05+_05_075+_075)4. If you want to count the number of Model, you can use the following measure.
Measure 2 = var _025 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]<0.25 && 'data table'[Model]=MAX('Table'[Model]))) var _025_05 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.25&&[Test]<0.5 && 'data table'[Model]=MAX('Table'[Model]))) var _05_075 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.5&&[Test]<0.75 && 'data table'[Model]=MAX('Table'[Model]))) var _075 = CALCULATE(DISTINCTCOUNT('data table'[Model]),FILTER('data table',[Test]>=0.75&& 'data table'[Model]=MAX('Table'[Model]))) return SWITCH( TRUE(), MAX('Table'[Value]) = "<0.25",_025, MAX('Table'[Value]) = "0.25-0.5",_025_05, MAX('Table'[Value]) = "0.5-0.75",_05_075, MAX('Table'[Value]) = ">0.75",_075, MAX('Table'[Value]) = "Total",_025+_025_05+_05_075+_075)The SWITCH function means that when the current column is equal to a certain value, output the corresponding value.
For example, when Table[Value] = “<0.25”, then output the value conforming to <0.25.
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
- Sujit_Thakur6 years agoSolution Sage
Thanks v-zhenbw-msft
You have helped me a lot .
One last doubt ,
What if my data grown , does it will hamper the Visualization calculation speed ?
Like now I have only 5 names , what if tomorrow I get data for 5000 names then the crossjoin table would size almost 25000 rows ? I just wanted to ask will this hamper my models efficiency ? About how much space it will take ?
Please help
- v-zhenbw-msft6 years agoCommunity Support
Hi Sujit_Thakur ,
Sorry for that we have not tested how much space it takes up when it groups.
It has little effect on the speed of visualization, if your data is not very very large, but remember the more data that a visual needs to display, the slower that visual is to load.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.