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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Rui_Reis
Frequent Visitor

Average of summary

Hello, guys! I'm creating a measure where I summaryze 3 kpi's from the same data base differently, for 2 of them is quite simple, but when it comes to the last one, I'm not finding a good way to summarize it. The WD are summarized as sum when they are from the same month and different locations, but when I summaryze the months, should do an average.

 

I tried to create a virtual table summarizing as a sum from the original DB and summarize again as an average from the virtual table, but it doesn't work and I feel like this is happening because my slicers are filtering the original DB.

 

Do you have a better way to do it or can you guide me what I'm doing wrong here?

 

 

Rui_Reis_1-1684240169540.png

 

Code:

KPI 1 =
VAR table1=SUMMARIZE(FILTER(Data_Base,Data_Base[KF]="DR"),Data_Base[Year],Data_Base[Date],Data_Base[KF],"DR",SUM(Data_Base[Value]))

return
IF(
    SELECTEDVALUE('KPI I'[KF])="DR",
    CALCULATE(AVERAGEX(table1,[DR]),Data_Base[PO]=SELECTEDVALUE('KPI I'[PO]),Data_Base[Year]=SELECTEDVALUE('KPI I'[Year])),
    IF(OR(SELECTEDVALUE('KPI I'[KF])="Fleet",SELECTEDVALUE('KPI I'[KF])="COIN"),
        CALCULATE(SUM(Data_Base[Value]),Data_Base[Date]=MAX(Data_Base[Date]),Data_Base[PO]     =SELECTEDVALUE('KPI I'[PO]),Data_Base[Year]=SELECTEDVALUE('KPI I'[Year]),Data_Base  [KF]=SELECTEDVALUE('KPI I'[KF])),
        CALCULATE(SUM(Data_Base[Value]),Data_Base[PO]=SELECTEDVALUE('KPI I'[PO]),Data_Base[Year]=SELECTEDVALUE('KPI I'[Year]),Data_Base[KF]=SELECTEDVALUE('KPI I'[KF]))))
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Rui_Reis,

For the multiple level aggregation, you should consider using SUMMARIZE function and iterator functions(e.g. SUMX, AVERAGEX...) to apply different level aggregations.

Measure Totals, The Final Word 

Also, you can use ISINSCOPE or ISFILTERED functions to check the different level of row context level and apply different type of calculate expressions.

Use IsInScope to get the right hierarchy level in DAX - Kasper On BI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Rui_Reis,

For the multiple level aggregation, you should consider using SUMMARIZE function and iterator functions(e.g. SUMX, AVERAGEX...) to apply different level aggregations.

Measure Totals, The Final Word 

Also, you can use ISINSCOPE or ISFILTERED functions to check the different level of row context level and apply different type of calculate expressions.

Use IsInScope to get the right hierarchy level in DAX - Kasper On BI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors