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
nbidark
Regular Visitor

Measure with IF statement in DATE

I am new to this community and looking for help with a measure having IF statement using dates.

I have fiscal year to date Operating Revenue, but I would like to calculate monthly operating revenue, so I used the parallel period function. 

Parallel Period Operating Revenue = CALCULATE(SUM('Revenue Table'[Total Operating Revenue]), PARALLELPERIOD('Revenue Table'[As of Date], -1, MONTH) )

 

Monthly Operating Revenue = [Total Operating Revenue] - [Parallel Period Operating Revenue].

My problem - The fiscal year is January to December. I do not want this formula to do the calculation for month of January, because January is the first month.  I want the calculation to apply from Feb.

 

I want to acheive (writing in simple english) - IF ( Month = "January", [Total Operating Revenue] Else [Monthly Operating Revenue]. 

Please help me write an appropriate measure.

 

Sample Data

As of DateProductOperating Revenue 
1/31/2020A50
2/29/2020A65
3/31/2020A72
4/30/2020A94
5/31/2020A105
6/30/2020A118.9
7/31/2020A132.8
8/31/2020A146.7
9/30/2020A160.6
10/31/2020A174.5
11/30/2020A188.4
12/31/2020A202.3
1/31/2021A32
2/28/2021A45
3/31/2021A63
4/30/2021A74
5/31/2021A89.5
6/30/2021A103.9
7/31/2021A118.3
8/31/2021A132.7
9/30/2021A147.1
10/31/2021A161.5

 

Thank you very much.

 

1 ACCEPTED SOLUTION
YukiK
Impactful Individual
Impactful Individual

You can use a measure like this:

Monthly Operating Revenue =
VAR __SelectedMonth = SELECTEDVALUE( DateDim[Month] )
VAR __MonthlyOperRev = 
IF ( __SelectedMonth  = "January", "Whatever you want in case of January", [Total Operating Revenue]-[Monthly Operating Revenue],   )
RETURN
__MonthlyOperRev 

 

Please give it a thumbs up if this helps!

View solution in original post

5 REPLIES 5
v-stephen-msft
Community Support
Community Support

Hi @nbidark ,

 

Here's my solution.

1.Create a calendar table.

Calendar =
ADDCOLUMNS (
    CALENDARAUTO ( 1 ),
    "YearMonth", FORMAT ( [Date], "YYYY-MMM" ),
    "Year", YEAR ( [Date] )
)

vstephenmsft_0-1640597244138.png

The relationship is as follows.

vstephenmsft_1-1640597301430.png

 

 

2.Create a measure.

Revenue =
IF (
    MONTH ( MAX ( 'Calendar'[Date] ) ) = 1,
    CALCULATE (
        SUM ( 'Table'[Operating Revenue ] ),
        FILTER ( ALLSELECTED ( 'Calendar' ), [Year] = MAX ( 'Calendar'[Year] ) )
    ),
    SUM ( 'Table'[Operating Revenue ] )
)

 

3.Results.

vstephenmsft_2-1640597375288.png

You can check more details from the attachment.

 

 

Best Regards,

Stephen Tao

 

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

 

Thank you very much for the detailed answer. Really appreciate your time.

YukiK
Impactful Individual
Impactful Individual

You can use a measure like this:

Monthly Operating Revenue =
VAR __SelectedMonth = SELECTEDVALUE( DateDim[Month] )
VAR __MonthlyOperRev = 
IF ( __SelectedMonth  = "January", "Whatever you want in case of January", [Total Operating Revenue]-[Monthly Operating Revenue],   )
RETURN
__MonthlyOperRev 

 

Please give it a thumbs up if this helps!

amitchandak
Super User
Super User

@nbidark , You should use date table for time intelligence and date table should be marked as date table

 

Parallel Period Operating Revenue = CALCULATE(SUM('Revenue Table'[Total Operating Revenue]), PARALLELPERIOD('Date'[Date], -1, MONTH) )

 

or

 

Parallel Period Operating Revenue = CALCULATE(SUM('Revenue Table'[Total Operating Revenue]), dateadd('Date'[Date], -1, MONTH) )

 

 

Thank you for replying. I understand the parallel period part, I am stuck with the part where I want to avoid the calculation for month of January. Can you help me with writing a measure for that. I have mentioned it in the original post. 

 

 

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.