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
leahYan
Advocate II
Advocate II

Running total in matrix with dynamic switch condition

Hi,

 

I have a DAX formula to accumulate the value, running total, and the different total overtime periods:

R-Acc is the running total of Acc, R-Com is the running total of Com. Remaining is the difference of two running total.

 

If there is no data in May, the Remaining doesn't show the prior value, the column total is also blank at the right end.

 

Com measure is similar to Acc, just filtering another value in the same field

 

Untitled.png

I tried to use a max(date) to limit the display range, but it doesn't make any change.

R-Acc =
var lastd = MAX('Query'[date])
return
IF(SELECTEDVALUE(Query[Daytype])<>"Work Day",
CALCULATE(
    [Acc],
    FILTER(
        ALL('Date'[Date]),
        'Date'[Date]<=lastd)
    )
)
 
Remaining =
SWITCH(SELECTEDVALUE(Query[Category1]),
"1.Direct Income",[R-Com]-[R-Acc],
"2.Direct Expense",if(SELECTEDVALUE(Query[Daytype])= "Work Day",BLANK(),[R-Com]-[R-Acc]),
"3.Gross Profit", [R-Com]-[R-Acc]+SUMX(FILTER(Query,[Daytype]="Work Day"),Query[GrossProfit]*Query[payrate2]/60),
"5.Net Profit",[R-Com]-[R-Acc]+SUMX(FILTER(Query,[Daytype]="Work Day"),Query[NetProfit]*Query[payrate2]/60)
)
 
eQuery and Date table relationship as below:
 

Capture0.PNG

Any thoughts would be very gratefully received.

 

Thanks!

2 REPLIES 2
Greg_Deckler
Super User
Super User

@leahYan - Extremely difficult to follow. If I am reading this correctly, I am thinking this is what you need: https://community.powerbi.com/t5/Quick-Measures-Gallery/The-New-Hotness-Custom-Matrix-Hierarchy/m-p/...

 

But, I could be majorly off. But, it looks like you are fighting with a matrix and that is a way to specifically control a matrix.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hi Greg_Deckler,

Thank you for your reply, but I am afraid that's not the issue. The issue is when a month has no data in Acc or Com, the running total of Acc or Com is blank too, which is expecting to show the same value of the previous month.

I read other solutions for missing values in the running total, and most of them can be solved by refer to a continuous date column in the calendar table instead of the date column in the fact table.

I applied that in my data model, but it couldn't solve my problem.

thank you very much.

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