Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Pdawar
Frequent Visitor

Sum of Max at row level in a measure with filters

Hi,

 

I want to be able to create a calculation at row level in a measure without adding a calculated column. In my Patient data, I want to calculate the sum of patients for each month but before calculating sum, I want to apply a condition at row level which is Max(Patients, 0).

 

I am able to achieve this using the following measure - 

test - Max at row level = CALCULATE(SUMX(Patients,MAX(Patients[Patients],0)))
Pdawar_1-1702029122981.png

 

 
But I want to able to apply filters like Type = "Paid" and Product = "Product A" and I am not sure how to that in the above mesure so that it keeps the calculation intact.
Pdawar_0-1702029075448.png

 

 
Please let me know if you have any solutions. The client is not keen on adding a column in the data and wants to calculate everything in a measure.
 
Thanks!
1 ACCEPTED SOLUTION

@Pdawar Sorry yes that will not work.  

For having that flexibility to use filter from dimension row wise. You can try using CALCULATETABLE DAX function. 

Max at row level  =
var _filteredPatientstable = CALCULATETABLE(Patients ,Patients[TYPE] = "Paid", product[Product]="Product A" )

return SUMX(_filteredPatientstable, MAX(Patients[Patients] )

I think this can work for your use case.




View solution in original post

6 REPLIES 6
Pdawar
Frequent Visitor

@saurabhtd thank you! Yes this works.

Pdawar
Frequent Visitor

I tried this logic to filter but this doesn't work because the first argument of filter function is to provide the table name and in this case we are not providing a table for Product column.

@Pdawar Sorry yes that will not work.  

For having that flexibility to use filter from dimension row wise. You can try using CALCULATETABLE DAX function. 

Max at row level  =
var _filteredPatientstable = CALCULATETABLE(Patients ,Patients[TYPE] = "Paid", product[Product]="Product A" )

return SUMX(_filteredPatientstable, MAX(Patients[Patients] )

I think this can work for your use case.




saurabhtd
Resolver II
Resolver II

@Pdawar  You can apply those filter inside FILTER DAX Fuction and then apply the SUMX on that filtered table. You can try the below formula. 

Max 
at row level  = 
var _filteredPatientstable = FILTER(Patients,Patients[TYPE]="Paid" && Patients[Product]="Product A")
return 
SUMX(_filteredPatientstable, MAX(Patients[Patients] )

Thank you! And can filter from another table can also be applied? So the data model is star schema and the product filter needs to be applied from the Product table.

@Pdawar If the data model is star schema then you can apply the filter condition in FILER DAX function from Product dimension. But there needs to be relationship between fact and dimesion. 
for example : 
Max at row level  = 
var _filteredPatientstable = FILTER(Patients,Patients[TYPE]="Paid" && product[Product]="Product A")
return 
SUMX(_filteredPatientstable, MAX(Patients[Patients] )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.