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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Create a measure and calculate Month on Month different by Name

Hello

 

Any idea how can I create a measure to show previous month balance per Name?

My aim is to calculate Month on Month difference using a slicer.

 

YearMonthName Balance 
2019AprilAmy     14,043.40
2019AprilBill       8,761.53
2019AprilJimmy     10,115.35
2019MayAmy       5,011.72
2019MayBill     22,128.64
2019MayJimmy           452.33
2020AprilAmy     24,801.22
2020AprilBill           737.87
2020AprilJimmy       7,565.99
2020MayAmy     26,527.03
2020MayBill       2,304.00
2020MayJimmy       8,167.68
2021AprilAmy       1,245.68
2021AprilBill             44.61
2021AprilJimmy       6,904.36
2021MayAmy       1,140.34
2021MayBill             31.22
2021MayJimmy       2,054.26

 

Heaps thanks,

Jess

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous  ,


You could first create a currentdate column by year and month, and then calculate the Balance of the previous month and the difference of month and month.

First create a column:

Currentdate =DATE ( [Year], MONTH ( CONVERT ( [Month] & " 1", DATETIME ) ), 1 )

v-yalanwu-msft_0-1619589292102.jpeg

Then create a Measure :

Previous Balance =
CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], -1, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] ))

And if you want to calculate the difference, you could create another measure :

Difference =
CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], 0, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] )
)
- CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], -1, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] )
)

The final output is shown below:

v-yalanwu-msft_1-1619589389524.pngv-yalanwu-msft_2-1619589392551.png


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous  ,


You could first create a currentdate column by year and month, and then calculate the Balance of the previous month and the difference of month and month.

First create a column:

Currentdate =DATE ( [Year], MONTH ( CONVERT ( [Month] & " 1", DATETIME ) ), 1 )

v-yalanwu-msft_0-1619589292102.jpeg

Then create a Measure :

Previous Balance =
CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], -1, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] ))

And if you want to calculate the difference, you could create another measure :

Difference =
CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], 0, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] )
)
- CALCULATE (
SUM ( [ Balance ] ),
PARALLELPERIOD ( 'Table'[Currentdate], -1, MONTH ),
ALLEXCEPT ( 'Table', 'Table'[Name] )
)

The final output is shown below:

v-yalanwu-msft_1-1619589389524.pngv-yalanwu-msft_2-1619589392551.png


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-yalanwu-msft 

You saved my life 😀. Thank you so much.

That's exactly what I need. I think ALLEXCEPT function fits my needs.

You are brilliant.

Thanks,

Jess

Anonymous
Not applicable

Hi @amitchandak 

 

Thanks for your quick response. Don't know why the LM balance didn't work.

Please see below:

In my original data, there only have month year. So, I use power query date to split then I add a column "Calendar date" it did the similar as your Date setting.

 

calendar date.JPG

 

From your measure, I can get MTD balance (using your first line) i.e. current month balance

However the last month balance is not working. Tried your line 2 ,please see below but it return nothing.

line 3 measure also return nothing.

 

biquetion.JPG

 

The weird thing is when I took out the Sum....[Balance] part, it can locate the last month data.

biquestion1JPG.JPG

What am i missing?

Heaps thanks,

Jess

 

 

 

 

 

amitchandak
Super User
Super User

@Anonymous , You can create a date like this using month year

Date = "01-" & [Month] & "-" & [year] // Change data type to date

 

Then use a date table and time intelligence to deal with it

 

examples

 

MTD Sales = CALCULATE(SUM(Table[balance]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Table[balance]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Table[balance]),previousmonth('Date'[Date]))

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.