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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Using IFs in DAX

Hello.

 

I am new to PBI and I am struggling to get some DAX measures right, and I believe my problem is in understanding the IF function. And maybe using Calculate correctly to filter the information.

 

My idea is to get a table like this and add two more columns with the Confirmed Revenue and the Revenue Total, that follow the bellow structure (the highlighted is the database name and after it is the field used):

FinalResult.PNG

ConfirmedRevenue.PNGRevenueTotal.PNG

I am using this FactTable in order to get the information, since I created a Type column to identify from which database the information came from:

AppendedTable.PNG

 

The Dates FactTable used and the Posted table structure is shown bellow:

FactTableDates.PNGPostedTable.PNG

(the Posted table has the first day of the month as date, but it is irrelevant since we will use the month to group)

 

Can anyone help me write the two DAX measures for Confirmed Revenue and Revenue Total?
Help is much apreciated 🙂

Thanks in advance!

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

Hi @Anonymous ,

 

You can try this method:

Sample data:

vyinliwmsft_0-1669965163757.png

New measures:

CONFIRMED REVENUE = 
VAR _Staff =
    CALCULATE (
        SUM ( 'Fact Staffing forecast'[Revenue DKK] ),
        FILTER (
            'Fact Staffing forecast',
            'Fact Staffing forecast'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
VAR _actual =
    CALCULATE (
        SUM ( 'Fact NAV actual month'[Revenue DKK] ),
        FILTER (
            'Fact NAV actual month',
            'Fact NAV actual month'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes",
        0,
        IF (
            MAX ( 'DimDates'[Month Number] ) = MONTH ( TODAY () ),
            _actual + _Staff,
            _Staff
        )
    )
REVENUE TOTAL =
VAR _budget =
    CALCULATE (
        SUM ( 'Fact NAV budget'[Revenue DKK] ),
        FILTER (
            'Fact NAV budget',
            'Fact NAV budget'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
RETURN
    IF ( SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes", _budget, [CONFIRMED REVENUE] )

The result is:

vyinliwmsft_1-1669965257430.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

2 REPLIES 2
Anonymous
Not applicable

Hello.

 

Thank you so much for the help.

 

I have been trying to go through the code, but I feel that solution is more complicated than the required since all the tables are connected through the Date in the DimDates table. The sample Data model would be more like this:

 

DataModel.PNG

 

And we want the ActualPL from the FactNAV Budget, I am so sorry for the error.

 

Could you please revise these and help me adapt the code above?

v-yinliw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can try this method:

Sample data:

vyinliwmsft_0-1669965163757.png

New measures:

CONFIRMED REVENUE = 
VAR _Staff =
    CALCULATE (
        SUM ( 'Fact Staffing forecast'[Revenue DKK] ),
        FILTER (
            'Fact Staffing forecast',
            'Fact Staffing forecast'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
VAR _actual =
    CALCULATE (
        SUM ( 'Fact NAV actual month'[Revenue DKK] ),
        FILTER (
            'Fact NAV actual month',
            'Fact NAV actual month'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes",
        0,
        IF (
            MAX ( 'DimDates'[Month Number] ) = MONTH ( TODAY () ),
            _actual + _Staff,
            _Staff
        )
    )
REVENUE TOTAL =
VAR _budget =
    CALCULATE (
        SUM ( 'Fact NAV budget'[Revenue DKK] ),
        FILTER (
            'Fact NAV budget',
            'Fact NAV budget'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
        )
    )
RETURN
    IF ( SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes", _budget, [CONFIRMED REVENUE] )

The result is:

vyinliwmsft_1-1669965257430.png

Hope this helps you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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