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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ashas
Frequent Visitor

How to calculate total for each category for specific MONTH context

Hi Folks,

 

I've had this issue for days and can't resolve it, have searched and posted in a couple of places. So instead of specifying my problem with code I've used. I'll try to explain what I'm trying to do and hope to get some hints!

 

So I have the following data model for a persoanl finance dashboard. Linking Transactions, Date, Categories and Budget table

 

ashas_0-1683870601978.png

 

And, the dashboard looks like this..

 

ashas_1-1683870727013.png

 

I want to be able to do the following..

When I click on the FY button, the last transaction date for that financial year will be displayed (so for FY23 its currenlty May 08 2023) 

So If I were to click FY 22, that date would be the last transaction date in FY22 (which happens to be June 30 2022)

 

The table shows the categories and I'm trying to work out the "Current month spend" for each category for the most recent month in which ever FY I click..

 

So for FY23, I would want to see  for each category the sum of all transactions in MAY FY23 only

For FY22, because the last transaction date is in JUNE, then I would expect to see the sum of all transactions in JUN FY22 only

 

I have tried EVERYTHING that I can think of.... I nearly have it... the problem I have is If there is a category that does not have a transaction in MAY FY23, then the total shown is for APR FY23 (The "Kids activities" shown in the table above is an example of this)

 

I realise it's a context thing, but I have no idea how to fix this - hoping for some tips or even blog posts to read up on.

 

Thanks folks!

Asha

 

1 REPLY 1
johnt75
Super User
Super User

Add a column to your date table called Today or Before which returns true if the date <= TODAY(), then you can try

Current month spend =
VAR ReferenceDate =
    CALCULATE ( MAX ( 'Date'[Month number] ), 'Date'[Today or before] = TRUE () )
VAR Result =
    CALCULATE (
        SUM ( 'Transactions'[Amount] ),
        'Date'[Month number] = ReferenceDate
    )
RETURN
    Result

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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