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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
charlessutton
Frequent Visitor

Help with If Function in Measure

I have two data tables and a calendar table. The data tables actual values by month and forecasted values by month. I would like to display the value of either actual or forecast based on the month. Previous months = actual current and future months = forecast. 


When I write the measure with an If function I cannot use the calendar table/columns in the expression. What am I missing? 

1 ACCEPTED SOLUTION

I can't see how that will work over the year end. I recommend adding a calc column that determines if the date has passed, or is in the future. Eg

Status=IF(calendar[date]<today(),"past","future")

then write a measure

=IF(SELECTEDVALUE(Calendar[Status])="Past",[Actual],[Forecast])



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

4 REPLIES 4
MattAllington
Community Champion
Community Champion

This is what I would do

1. Create a matrix visual and put calendar month on rows (ideally YYYY-MMM or similar). You can also nest year and month and expand the matrix. 

2. Write the actual measure and place in values

3. Write the forecast measure and place in values

4 write a test measure max(actual[date]) and place in values

 

See if you can work it out from there. Preparing your data in a visual so you can see what is going on is one of the most important habits you can follow when learning DAX. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Thank you for the reply. That is essentially what I have done. I am having a problem with an if statement. It will not recognize my Calendar Table/Columns as part of the function. I am trying to write a measure like this 

if(month(calendar[date]) < month(today()), ActualValue, ForecastValue) 

 

this would logically populate the actual values in the previous months and forecast values in current/future months. 

Hi  @charlessutton ,

 

Have you create relationships between data tables and date table?

v-kelly-msft_0-1616554123772.png

It works fine here using below dax expression:

Measure = IF(MONTH(MAX('calendar table'[Date]))<MONTH(TODAY()),MAX('Actuals values'[value]),MAX('forecast values'[value]))

And you will see:

v-kelly-msft_1-1616554269526.png

For my sample .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

I can't see how that will work over the year end. I recommend adding a calc column that determines if the date has passed, or is in the future. Eg

Status=IF(calendar[date]<today(),"past","future")

then write a measure

=IF(SELECTEDVALUE(Calendar[Status])="Past",[Actual],[Forecast])



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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