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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply

How to create a measure, which shows me remaining values by months

Hello All,

 

I am strugling with creating a measure, which shows me for particular months what values we have still to remain. Simple, substracting values from previous period at the begginning and later from values what we already have next value from next month. Here is a sample data:

MonthHighRemaining
1/1/2025 8787
2/1/2025 2760
3/1/2025 2040
4/1/2025 00


In column Remaining is result, what i want to achieve. I dont have column Remaining in data, this is a RESULT to achieve

Thank you in advance

1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@Jakub_Poweska11 
Please create a measure based on below logic.
1) Create First Month High of all the Month.. That should be 87 for all the Month
2) Create Running total without taking the first  Month..
3) Then Differentiate it..
Now, i have one question why the last month is showing 0, if the last month high is 0 then remainig should be 40.. If it is by default 0 then below is the code

Remianing = 
VAR _FirstMonth = 
MONTH(
MINX(
 ALL('Table'[Month] ),
 [Month]
) )
VAR _LastMonth = 
MONTH(
MAXX(
 ALL('Table'[Month] ),
 [Month]
) )
VAR _FMH = 
CALCULATE(
    SUM( 'Table'[High] ),
FILTER( ALL( 'Table'),
MONTH( 'Table'[Month] ) = _FirstMonth
) )
VAR _MonthNumber = 
MONTH( MAX( 'Table'[Month] ) )
VAR _RT = 
CALCULATE(
    SUM( 'Table'[High] ),
FILTER( ALL( 'Table'),
MONTH( 'Table'[Month] ) > _FirstMonth &&
 MONTH( 'Table'[Month] ) <= _MonthNumber 
) )
VAR _Result = 
IF(
 MONTH( MAX( 'Table'[Month] )) = _FirstMonth,
 SUM( 'Table'[High] ),
 IF(
MONTH( MAX( 'Table'[Month])) = _LastMonth,0,
 _FMH - _RT
) )
RETURN
_Result

 

Just remove the last month logic from If statement if you want to show as 40..
I ahve tested with some other month and this is returning correct figure.. Below is the screenshot and complete file.

sanalytics_0-1745572449478.png

I must say this is very interesting problem, had to open power bi desktop and code. Thanks.. 

Hope this helps

 

Regards

sanalytics

View solution in original post

9 REPLIES 9
AntrikshSharma
Super User
Super User

@Jakub_Poweska11 

Total High = SUM ( 'Table'[High] )
Remaining High = 
VAR HighByMonth =
    ADDCOLUMNS ( 
        ALL ( 'Table'[Month] ), 
        "@High", [Total High] 
    )
VAR FirstMonthHigh =
    SELECTCOLUMNS (
        INDEX ( 1, HighByMonth, ORDERBY ( 'Table'[Month], ASC ) ),
        [@High]
    )
VAR RollingWindow =
    WINDOW ( 
        2, ABS, 0, REL,
        HighByMonth,
        ORDERBY ( 'Table'[Month], ASC )
    )
VAR RunningTotal =
    SUMX ( RollingWindow, [@High] )
VAR Result =
    IF (
        [Total High] = 0 || NOT ISINSCOPE ( 'Table'[Month] ),
        0,
        FirstMonthHigh - RunningTotal
    )
RETURN
    Result

 

@Jakub_Poweska11 I would prefer to do this in Power Query itself.

let
    Source = Table,
    Acc = List.Accumulate (
        List.Skip ( Source[High] ),
        { List.First ( Source[High] ) },
        ( s, c ) => s & { if c = 0 then 0 else List.Last ( s ) - c }
    ),
    Combine = Table.FromColumns (
        Table.ToColumns ( Source ) & { Acc },
        type table [ Month = date, High = number, Remaining = number ]
    )
in
    Combine
sanalytics
Super User
Super User

@Jakub_Poweska11 
Please create a measure based on below logic.
1) Create First Month High of all the Month.. That should be 87 for all the Month
2) Create Running total without taking the first  Month..
3) Then Differentiate it..
Now, i have one question why the last month is showing 0, if the last month high is 0 then remainig should be 40.. If it is by default 0 then below is the code

Remianing = 
VAR _FirstMonth = 
MONTH(
MINX(
 ALL('Table'[Month] ),
 [Month]
) )
VAR _LastMonth = 
MONTH(
MAXX(
 ALL('Table'[Month] ),
 [Month]
) )
VAR _FMH = 
CALCULATE(
    SUM( 'Table'[High] ),
FILTER( ALL( 'Table'),
MONTH( 'Table'[Month] ) = _FirstMonth
) )
VAR _MonthNumber = 
MONTH( MAX( 'Table'[Month] ) )
VAR _RT = 
CALCULATE(
    SUM( 'Table'[High] ),
FILTER( ALL( 'Table'),
MONTH( 'Table'[Month] ) > _FirstMonth &&
 MONTH( 'Table'[Month] ) <= _MonthNumber 
) )
VAR _Result = 
IF(
 MONTH( MAX( 'Table'[Month] )) = _FirstMonth,
 SUM( 'Table'[High] ),
 IF(
MONTH( MAX( 'Table'[Month])) = _LastMonth,0,
 _FMH - _RT
) )
RETURN
_Result

 

Just remove the last month logic from If statement if you want to show as 40..
I ahve tested with some other month and this is returning correct figure.. Below is the screenshot and complete file.

sanalytics_0-1745572449478.png

I must say this is very interesting problem, had to open power bi desktop and code. Thanks.. 

Hope this helps

 

Regards

sanalytics

One Question, what should i change if i want to use Month - Year (format Jan 2025 etc) from Calendar table. I have connection between tables Calendar Date and Month in Table. Changed to: 

Remaining High =
VAR _FirstMonth =
MONTH(
MINX(
 ALLSELECTED('Calendar'[Date] ),
 [Date]
) )
VAR _LastMonth =
MONTH(
MAXX(
 ALLSELECTED('Calendar'[Date] ),
 [Date]
) )
VAR _FMH =
CALCULATE(
    SUM( 'Secret Findings ITCC'[High] ),
FILTER( ALLSELECTED( 'Secret Findings ITCC'),
MONTH( 'Secret Findings ITCC'[Month] ) = _FirstMonth
) )
VAR _MonthNumber =
MONTH( MAX( 'Secret Findings ITCC'[Month] ) )
VAR _RT =
CALCULATE(
    SUM( 'Secret Findings ITCC'[High] ),
FILTER( ALLSELECTED( 'Secret Findings ITCC'),
MONTH( 'Secret Findings ITCC'[Month] ) > _FirstMonth &&
 MONTH( 'Secret Findings ITCC'[Month] ) <= _MonthNumber
) )
VAR _Result =
IF(
 MONTH( MAX( 'Secret Findings ITCC'[Month] )) = _FirstMonth,
 SUM( 'Secret Findings ITCC'[High] ),
 IF(
MONTH( MAX( 'Secret Findings ITCC'[Month])) = _LastMonth,0,
 _FMH - _RT
) )
RETURN
_Result
 
and its not working

@Jakub_Poweska11 
Requesting you to provide pbix file along with your data model.. Need to debugg why this not working..
As per your data shared.. it is working fine and showing expected output.

 

Regards,

sanalytics

I cant share my file. I have in Calendar[Date] whole days for month and you?

Thank you so much. Its working.

Requirement is that, when High is 0 it means that we removed all values

bhanu_gautam
Super User
Super User

@Jakub_Poweska11 Go to the "Modeling" tab.
Click on "New Column".
Enter the following DAX formula:

dax
Remaining =
VAR CurrentMonth = 'Table'[Month]
VAR CurrentHigh = 'Table'[High]
VAR PreviousRemaining =
CALCULATE(
MAX('Table'[Remaining]),
FILTER(
'Table',
'Table'[Month] < CurrentMonth
)
)
RETURN
IF(
ISBLANK(PreviousRemaining),
CurrentHigh,
PreviousRemaining - CurrentHigh
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam 
Sorry, but i dont have column Remaining in my data. I wrote in my first message that is a result, which i want to achieve. That was result example

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.