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
Anonymous
Not applicable

DAX Average over a previous SUM

Hello guys,

I'm trying to do an Average based on a previous Sum. I'm connecting to Snowflake which doesn't have the Query Editor feature yet.

Here is the sample of data and final desired result. I'm also sharing the query that resolve it from SQL. I need the same in DAX.

Thanks in advance!

 

Note: the colored rows are the ones can be grouped.

 

Data sample and desired result.

Capture-a.PNG

Query that gives me the result

SQL query to get the resultSQL query to get the result

9 REPLIES 9
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try it:

 

Measure = AVERAGEX(SUMMARIZE(TABLE, custono, payor1, patient, cpt, "Sum", SUM(units)), Sum)

 

Drag the fields: ustono, payor1, patient, cpt to the table and this new measure.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

camargos88  

I tried this: 

AVG_Units = AVERAGEX(SUMMARIZE(CHARGE,CHARGE[CUSTNO],CHARGE[PAYOR1],CHARGE[PATIENT],CHARGE[CPT],"SUMA",SUM(CHARGE[UNITS])),[SUMA])
and nothing. When I put the new measure to the table I got the same value as Total Units.

@Anonymous ,

Can you post the data as text here, so I can take a look ?



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

@camargos88 

Here's a sample

ID CUSTNO PAYOR1 PATIENT CPT UNITS
89049079 CustNo1 Payor1 Patient1 CPT1 1
87987720 CustNo1 Payor1 Patient1 CPT2 4
87918407 CustNo1 Payor1 Patient1 CPT1 1
87987786 CustNo1 Payor1 Patient2 CPT1 2
87987758 CustNo1 Payor1 Patient2 CPT9 1
87987758 CustNo1 Payor1 Patient2 CPT1 6
87987786 CustNo1 Payor2 Patient7 CPT1 3
87987758 CustNo1 Payor2 Patient7 CPT9 9
87987758 CustNo1 Payor2 Patient7 CPT2 6
87987759 CustNo1 Payor2 Patient7 CPT9 12

Anonymous
Not applicable

@camargos88 

I think the SUMMARIZE part is well reflecting the subquery to get TotalUnits, what I think it's missing it's the grouping part when it does the AVERAGE. Like I do in the external query.

@Anonymous ,

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

@camargos88 

For some reason it doesn't work for me. I'm attaching a more real data, maybe I was missing something important in the first sample. Would you mine take a look. https://www.dropbox.com/s/zdb0fqr7hnovp7g/Sample_Data.csv?dl=0 

Really appreciate your help.

Hi @Anonymous ,

Are you summaring the CUSTNO and PAYOR1 columns ? Maybe it's numerical columns and when you see the values it's wrong.

Try don't aggregating them or changing them to text data type.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

@camargos88 

It wasn't that, but I just confirmed that your first measure was fine!!!

THANKS A LOT!!

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.