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
Anonymous
Not applicable

NEED HELP WITH DAX FORMULA ( YTD ACTUAL + REMAINING BUDGET VS YTD BUDGET)

Hi all,

I wanted to create something using power BI which I have 2 sets of data comprise ACT and BUD within the same year.


Where I have my actual revenue for 3 months and 12 months of budget. But when I select my slicer accordingly to my months I need a projection something like below shown.

a.PNG

 

As I only have 3 months of actual, I need to compare 6 months of budget using 3 months actual and 3 month budget depend on the slicer chosen by the user (whether is up to 12 month or lesser). 


The structure of my data look like this: **I will unpivot ACT and BUD

Ops UnitIDMTHMTH ORDERACTBUD
AREVENUEJUL11020
AREVENUEAUG21020
AREVENUESEP31020
AREVENUEOCT4 20
AREVENUENOV5 20
AREVENUEDEC6 20
AREVENUEJAN7 20
AREVENUEFEB8 20
AREVENUEMAR9 20
AREVENUEAPR10 20
AREVENUEMAY11 20
AREVENUEJUN12 20
BREVENUEJUL110050
BREVENUEAUG210050
BREVENUESEP310050
BREVENUEOCT4 50
BREVENUENOV5 50
BREVENUEDEC6 50
BREVENUEJAN7 50
BREVENUEFEB8 50
BREVENUEMAR9 50
BREVENUEAPR10 50
BREVENUEMAY11 50
BREVENUEJUN12 50

 

Eg: When I select Dec then it give me something like this

Ops UnitFCT (3month actual + 3 month budget)BUD
A90120
B450300


I tried a few method but it seem unable to create what I wanted and also search within forum too. 


Is there any way I can do? Please help. Thank you.

 

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

Hi @Anonymous ,

 

If your table doesn’t have a date column, just have a month column, we can create a MTH table and two measures to meet your requirement.

Please pay attention, don’t create a relationship.

 

1. Create a table that contains MTH and MTH order.

 

slicer = SUMMARIZE('Table','Table'[MTH],'Table'[MTH ORDER])

 

Need1.jpg

 

2. Then we can use it to create a slicer.

 

need2.jpg

 

3. We can create two measures.

 

BUD measure = 
VAR _Select =
    SELECTEDVALUE ( slicer[MTH ORDER], 1 )
RETURN
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )

 

ACT measure = 
VAR _Select =
    SELECTEDVALUE ( slicer[MTH ORDER], 1 )
VAR _ACT =
    CALCULATE (
        SUM ( 'Table'[ACT] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )
VAR _max_act_month =
    CALCULATE (
        MAX ( 'Table'[MTH ORDER] ),
        FILTER ( 'Table', 'Table'[ACT] = MAX ( 'Table'[ACT] ) )
    )
VAR _BUD_max_act_month =
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _max_act_month
        )
    )
VAR _BUD =
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )
RETURN
    IF ( _Select > _max_act_month, _BUD_max_act_month + _ACT, _ACT + _BUD )

 

need3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

If your table doesn’t have a date column, just have a month column, we can create a MTH table and two measures to meet your requirement.

Please pay attention, don’t create a relationship.

 

1. Create a table that contains MTH and MTH order.

 

slicer = SUMMARIZE('Table','Table'[MTH],'Table'[MTH ORDER])

 

Need1.jpg

 

2. Then we can use it to create a slicer.

 

need2.jpg

 

3. We can create two measures.

 

BUD measure = 
VAR _Select =
    SELECTEDVALUE ( slicer[MTH ORDER], 1 )
RETURN
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )

 

ACT measure = 
VAR _Select =
    SELECTEDVALUE ( slicer[MTH ORDER], 1 )
VAR _ACT =
    CALCULATE (
        SUM ( 'Table'[ACT] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )
VAR _max_act_month =
    CALCULATE (
        MAX ( 'Table'[MTH ORDER] ),
        FILTER ( 'Table', 'Table'[ACT] = MAX ( 'Table'[ACT] ) )
    )
VAR _BUD_max_act_month =
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _max_act_month
        )
    )
VAR _BUD =
    CALCULATE (
        SUM ( 'Table'[BUD] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Ops Unit] = MAX ( 'Table'[Ops Unit] )
                && 'Table'[MTH ORDER] <= _Select
        )
    )
RETURN
    IF ( _Select > _max_act_month, _BUD_max_act_month + _ACT, _ACT + _BUD )

 

need3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

Anonymous
Not applicable

Hi Zhenbw,

WOW. It seems like what I needed for my dashboard.

 

Let me try and will get back to you see asap as I just return back to work.

Anonymous
Not applicable

Hello, @v-zhenbw-msft 

 

Sorry can trouble you to share you pbix file as I it written it incompatible with my current version of Power BI desktop.

Even after redownload it, it seems that still appear this issue.

 

Please advise? Thanks.

Hi @Anonymous ,

 

Please try the Power BI Store version.

 

N1.jpg

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , In case you do not have date

create one like

date = Date(Table[Year], table[MTH], 1) //Numeric month

 

then use date table and time intelligence

YTD Act= CALCULATE(SUM(Table[ACT]),DATESYTD('Date'[Date],"12/31"))

YTD Bud= CALCULATE(SUM(Table[BUD]),DATESYTD('Date'[Date],"12/31"))

 

Power BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

In case you do not have month as a number - refer first few mins of this video

https://www.youtube.com/watch?v=yPQ9UV37LOU&t=30s

Anonymous
Not applicable

Hi Amit, 

Thanks for your YTD DAX formula but it does not solved my issue having both actual and budget together.


Anyway thanks for your help. 

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.