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.
Hi Sujit_Thakur
Add this table to your model. I have named this HP-OP-Bounds.
After that create two calculated columns(HP/OP and Bin) as shown below in your table. I have named this table 'HP-OP'.
The formulaes for calculated columns are shown below.
HP/OP = DIVIDE('HP-OP'[HP], 'HP-OP'[OP], 0)
Bin =
VAR X = 'HP-OP'[HP/OP]
VAR Filtered =
FILTER (
'HP-OP-Bounds',
VAR Y = 'HP-OP-Bounds'[Upper Bound] RETURN 'HP-OP-Bounds'[Lower Bound] <= X
&& IF ( ISBLANK ( y ), TRUE (), Y > X )
)
RETURN
MAXX ( Filtered, 'HP-OP-Bounds'[Bin] )
Now use matrix visual as shown below.
Hope this helps.
Appreciate with kudos.
Please mark it as solution if this resolves your problem.
Thanks
Dear friend Anonymous ,
Can I create this same using measure , as I want to later use date slicer , using calculated columns will not help me when I want HP/OP to be recalculated every time I change date range .
You seriously brought me much closer to ans , please answer how can I achieve by using HP/OP as a calculated measure , because as you can see I have date column too of which I will add date slicer .