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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
H_insight
Helper V
Helper V

Calculate Subtotal From a Template - Finance

Hiya,

 

I am using a custom template (Disconnected table) inside power bi to help me deliver a business layout.

 

Template:

H_insight_0-1688679651339.png

 

I have created the following measures:

Base measure: 

Total Amount = SUM('FACT'[Value])

 

Amount measure for Plan & Actual:
Amount (,000) =

VAR _Actual = CALCULATE([Total Amount], 'FACT'[Plan] = "A")
VAR _Plan = CALCULATE([Total Amount], 'FACT'[Plan] = "P")

Return
IF(
SELECTEDVALUE('Custom View'[Type]) = "Actual", _Actual,
IF(SELECTEDVALUE('Custom View'[Type]) = "Plan", _Plan,
IF(SELECTEDVALUE('Custom View'[Type]) = "VAR", (_Plan - _Actual),0)))+0


Dynamic measure to get me values per selected (In month , YTD, Full Year)


Dynamic Measure =
VAR _CurrentItem = SELECTEDVALUE(Template[SK])
VAR _Title = SELECTEDVALUE('Custom View'[Title])
VAR _Type = SELECTEDVALUE('Custom View'[Type])
VAR _InMonth = CALCULATE( [Amount (,000)], FILTER('FACT','FACT'[SK] = _CurrentItem))
VAR _category = SELECTEDVALUE(Template[Category])

VAR _YTD = CALCULATE(
[Amount (,000)],
FILTER(ALL('Calendar'), 'Calendar'[Date] IN DATESYTD('Calendar'[Date])),
'FACT'[SK] = _CurrentItem
)

VAR _FullYear = CALCULATE(
[Amount (,000)],
FILTER(ALL('Calendar'), 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year])),
'FACT'[SK]= _CurrentItem
)

Return
SWITCH(TRUE(),
_Title = "In Month", _InMonth,
_Title = "YTD", _YTD,
_Title = "Full Year", _FullYear,
BLANK()
)


The below matrix shows the correct values, but what I am struggling to get is the SubTotals per the layout.

i.e. "Finance Subtotal" = (SK1+SK2+SK3+SK4)

 

Missing Output:

H_insight_1-1688679740029.png

 

Any help is greatly appreciated.

 

Attached sample PBIX File .

Many thanks

2 REPLIES 2
Greg_Deckler
Super User
Super User

@H_insight First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler .

It's remarkable to realize that this concept was initially proposed back in July 2018, and its 5 YEARS anniversary is fast approaching without any resolution in sight!


I see your approach of having "No Calculate", but for some reason, I am not able to apply it to my disconnected table. any chance you can provide the DAX code for me to explorer, please?

 

So far, here is my attempt:

m_Total 4 =
VAR __table = SUMMARIZE('FACT','FACT'[SK], 'FACT'[Date], 'FACT'[Plan],"__value",[Total Amount])
RETURN
IF(HASONEVALUE(Template[SK]),[Total Amount],SUMX(__table,[__value]))
but I am getting the same values everywhere, which is normal as there is no relationship between 'Template' and 'FACT' tables.

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors