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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
carlochecchia
Helper I
Helper I

Calculate SUM for last period

Dear all,

 

Could you please help me solving one issue?

 

I have the following table where i have a few items, a store name  and the amount they are worth.

 

PERIODDATESTORENETWORTH
201701jan/17A100
201701jan/17B200
201701jan/17A300
201701jan/17C100
201701jan/17D100
201702feb/17A200
201702feb/17C300
201702feb/17A100
201702feb/17C200
201702feb/17A300
201702feb/17D300
201703mar/17D100
201703mar/17B100
201703mar/17A100
201703mar/17C200
201703mar/17A300
201703mar/17B100
201703mar/17A200
201703mar/17C300

 

                        period
 201701201702201703 
A400600600
B200 200
C100500500
D100300100
total  networth8001.4001.400

 

I would like to report a table with the sum of the networth, per store, for the last period available (in this case - march 17 - 201703)

 

I tried to create a measure where  i would calculate the sum of the networth for the LAST PERIOD:

NetWorth.Sum.Last.Period = calculate( sum('Table'[NETWORTH]) ; lastdate('Table'[DATE] ))

 

Unfortunately, this is not working properly when I use the data slicers.

 

When set the slicer for the period feb 2017, it gives the wrong results:

 

STORE201702_WRONG201702_CORRECT
A600600
B200 
C500500
D300300
TOTAL1.6001.400

 

 

The reason for this error is because the formula LASTDATE  returns the last non Blank Value. Therefore it returns 200 ( for the B store  ) when it should return ZERO.

 

How I can fix this formula to get the amount only for the last period avaliable?

 

Thanks in advance

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @carlochecchia,

 

Can you share your pbix file please? I tested your scenario. It worked fine.

Calculate_SUM_for_last_period

 

 

Best Regards,

Dale

Community Support Team _ Dale
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

3 REPLIES 3
v-jiascu-msft
Employee
Employee

Hi @carlochecchia,


Could you please mark the proper answer as solution?

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @carlochecchia,

 

Can you share your pbix file please? I tested your scenario. It worked fine.

Calculate_SUM_for_last_period

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Interkoubess
Solution Sage
Solution Sage

Hi @carlochecchia,

 

What about creating a calendar table and link it to your fact table and then creat a measure with time intelligence functions like previousmonth:

I created this measure and it seems to work:

NetWorth.Sum.Last.Period = calculate( sum('Table'[NETWORTH]) ; previousmonth('Calendar'[DATE] ))

 

 

Hope it helps...

NinterCapturesum.PNG

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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