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
Aardvark99
New Member

Converting Excel Syntax to DAX - status based on two dates

Hello Power BI Community!

I have some existing Excel syntax that has served me well, but I'm struggling to use it in Power BI.

 

I have a list of projects with a Start on Site Date (SOS) and a Grand Opening Date (GO).  I have previously used the below syntax to provide a status based on today's date; returning: TBC where the date is blank, Pending SOS, On Site, Complete.

 

=IF(E2="","TBC",IF(TODAY()<E2,"Pending SOS",IF(OR(E2>=TODAY(),TODAY()<=F2,F2=""),"On Site",IF(TODAY()>=F2,"Complete",))))

Where E2 = SOS Date
Where F2 = GO Date

 

Please can someone help me get this to work in Power BI?

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

Hi @Aardvark99 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1669862641421.png

Please try:

Measure =
VAR _a =
    MAX ( 'Table'[SOS Date] )
VAR _b =
    MAX ( 'Table'[GO Date] )
RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( _a ), "TBC",
        TODAY () < _a, "Pending SOS",
        OR ( TODAY () >= _a && TODAY () <= _b, TODAY () >= _a && ISBLANK ( _b ) ), "On Site",
        TODAY () >= _b, "Complete"
    )

Final output:

vjianbolimsft_1-1669862681040.png

Best Regards,

Jianbo Li

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

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @Aardvark99 ,

 

If you want to use it for matrix visualisations, pie charts or page filters, you may need to create a calculated column:

Status = 
VAR _a =
    CALCULATE(MAX ( 'Table'[SOS Date] ))
VAR _b =
    CALCULATE(MAX ( 'Table'[GO Date] ))
RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( _a ), "TBC",
        TODAY () < _a, "Pending SOS",
        OR ( TODAY () >= _a && TODAY () <= _b, TODAY () >= _a && ISBLANK ( _b ) ), "On Site",
        TODAY () >= _b, "Complete"
    )

Output:

vjianbolimsft_0-1670202694821.png

Best Regards,

Jianbo Li

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

 

Aardvark99
New Member

Hi Jianbo Li,

The DAX works perfectly in a table. 

However, I can't seem to use it for matrix visualisations, pie charts or page filters... I must be doing something wrong 😞 

v-jianboli-msft
Community Support
Community Support

Hi @Aardvark99 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1669862641421.png

Please try:

Measure =
VAR _a =
    MAX ( 'Table'[SOS Date] )
VAR _b =
    MAX ( 'Table'[GO Date] )
RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( _a ), "TBC",
        TODAY () < _a, "Pending SOS",
        OR ( TODAY () >= _a && TODAY () <= _b, TODAY () >= _a && ISBLANK ( _b ) ), "On Site",
        TODAY () >= _b, "Complete"
    )

Final output:

vjianbolimsft_1-1669862681040.png

Best Regards,

Jianbo Li

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

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.

Top Solution Authors