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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Robin96
Helper II
Helper II

Running total problem

i have a switch case that is showing different values for each row in a matrix

i have a table that shows the income, expenses and my cashflow per week.

This is how the matrix should show values:
Row 1: show cashflow
Row 2: show net cashflow this week + previous week balance
row 3 and further: show net cashflow this week + the values from row 2

i have problem with row 3 and further.

This is the code i have now:

Cash balance =
var min_ = MIN('date'[year_week])

var cash_Balance =
CALCULATE(SUM(Manual_posts[amount]))

var cash_flow =
CALCULATE([Net cashflow])

VAR forrige_uke_cashflow =
CALCULATE([Net cashflow],FILTER(ALL('date'),[year_week]=SELECTEDVALUE('date'[year_week])-1))

VAR forrige_uke_cashbalance =
CALCULATE(cash_Balance,FILTER(ALL('date'),[year_week]=SELECTEDVALUE('date'[year_week])-1))

var calc_ = cash_flow - forrige_uke_cashflow

var net_cash_forrige_uke_balance =
[test (forrige uke cash balance)] + cash_flow

Var shadow_2 =
CALCULATE([TEST_cash balance_shadow2],FILTER(ALL('date'),[year_week]=SELECTEDVALUE('date'[year_week])-2))

var shadow =
[TEST_cash balance_shadow] + [Net cashflow]

var shadow2 =
shadow_2

VAR SWITCH_ =
SWITCH(
    TRUE(),
    SELECTEDVALUE('date'[year_week]) = calculate(MIN('date'[year_week]), ALLSELECTED('Date'[Week])),cash_Balance,
    SELECTEDVALUE('date'[year_week]) = calculate(MIN('date'[year_week])+1, ALLSELECTED('Date'[Week])),net_cash_forrige_uke_balance,
    SELECTEDVALUE('date'[year_week]) > calculate(MIN('date'[year_week])+1, ALLSELECTED('Date'[Week])),shadow,
    9
    )
RETURN SWITCH_


How can i make the third row calculate this weeks net cash and subsctract the last weeks balance

my date table have weeknumber column. and the report uses week and year slicer.

6 REPLIES 6
Robin96
Helper II
Helper II

Its still not giving me the correct result..

Greg_Deckler
Community Champion
Community Champion

@Robin96 Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

This is the data i have as test

Robin96_0-1709638604954.png


This is the expected output i want:
The orange fields is what i use for the the calculation, and the green field is where i want the result

Robin96_1-1709638872705.png

 

Hi

 

Please try this

Cashflow =
VAR minweek =
MIN ( RT[Week] )
VAR Firstcash =
CALCULATE ( MAX ( RT[Cash Balance] ), RT[Week] = minweek, ALL ( rt ) )
VAR Activweek = RT[Week]
VAR RTotal =
CALCULATE (
SUM ( RT[Net Cashflow] ),
RT[Week] > minweek
&& RT[Week] <= Activweek,
ALL ( RT )
)
VAR result =
IF ( Activweek = minweek, Firstcash, RTotal + Firstcash )
RETURN
result

 

JamesFR06_0-1709641742907.png

 

Hey,

Thanks for the response! This did not generate the desired outcome. i dont have every column in the same table as you have here. 

i also get an error on the syntax at "Activweek" not sure why, guess it needs an expression.

Robin96_0-1709642587109.png

 

Sorry I do not realize that you got informations in different tables

 

For Activweek, as you put it on a matrix use the selectedvalue(Date[Week])

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.