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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Polar_A
Helper I
Helper I

DAX If Statement

Hi can I get some help please.

I want to write an if statement so that if the shipping status is Complete then it only shows the most recent record based on the shipping date. This means that the shipping date of 08/02/2024 will be the record to show. I'm not sure if I need to group by the RefNumber:

 

ShippingDateDateCustomerAddedInvoiceRecvdDateShipping StatusRefNumber
09/04/202430/04/202430/04/2024Active23118616
15/09/202319/09/202319/09/2023Complete23109497
17/10/202319/09/202320/10/2023Complete23109497
08/02/202419/09/202314/02/2024Complete23109497

 

KR,

 

Polar

3 ACCEPTED SOLUTIONS
xifeng_L
Super User
Super User

Hi @Polar_A ,

 

If you want to add a new column to mark the data you need, then try the following expression.

 

xifeng_L_0-1715941726297.png

 

Column = 
VAR MaxShipDate = CALCULATE(MAX('Table'[ShippingDate]),ALLEXCEPT('Table','Table'[RefNumber]))
RETURN
IF('Table'[Shipping Status]="Complete" && 'Table'[ShippingDate]=MaxShipDate,1)

 

If you want to create a new table, then try the following table expression.

 

xifeng_L_1-1715941882392.png

 

Table 2 = 
FILTER(
    'Table',
    'Table'[Shipping Status]="Complete" &&
        'Table'[ShippingDate]=CALCULATE(MAX('Table'[ShippingDate]),ALLEXCEPT('Table','Table'[RefNumber]))
)

 

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

View solution in original post

mark_endicott
Super User
Super User

@Polar_A - You can do this with a measure by using the following DAX:

 

Show Record = 
VAR _ref =
    SELECTEDVALUE ( 'Table (4)'[RefNumber] )
VAR _ship_status =
    SELECTEDVALUE ( 'Table (4)'[Shipping Status] )
VAR _ship_date =
    SELECTEDVALUE ( 'Table (4)'[ShippingDate] )
VAR calc =
    CALCULATE (
        MAX ( 'Table (4)'[ShippingDate] ),
        FILTER ( ALL ( 'Table (4)' ), 'Table (4)'[RefNumber] = _ref )
    )
RETURN
    SWITCH (
        TRUE (),
        _ship_status <> "Complete", 1,
        IF ( CALCULATE ( calc, 'Table (4)'[RefNumber] = _ref ) = _ship_date, 1, 0 )
    )

 

You can then add the measure as a filter to the visual and set the value to 1, please see the screenshot below (you do not need the measure in the table, you can just add it to the filter pane):

 

mark_endicott_0-1715944554539.png

 

If this works for you, please accept it as the solution. 

 

 

View solution in original post

DataNinja777
Super User
Super User

Hi @Polar_A 

There are many ways to achive your required output, and one of them is as follows:

DataNinja777_0-1715944533291.png

I attach an example pbix file.  

Best regards,

View solution in original post

5 REPLIES 5
DataNinja777
Super User
Super User

Hi @Polar_A 

There are many ways to achive your required output, and one of them is as follows:

DataNinja777_0-1715944533291.png

I attach an example pbix file.  

Best regards,

mark_endicott
Super User
Super User

@Polar_A - You can do this with a measure by using the following DAX:

 

Show Record = 
VAR _ref =
    SELECTEDVALUE ( 'Table (4)'[RefNumber] )
VAR _ship_status =
    SELECTEDVALUE ( 'Table (4)'[Shipping Status] )
VAR _ship_date =
    SELECTEDVALUE ( 'Table (4)'[ShippingDate] )
VAR calc =
    CALCULATE (
        MAX ( 'Table (4)'[ShippingDate] ),
        FILTER ( ALL ( 'Table (4)' ), 'Table (4)'[RefNumber] = _ref )
    )
RETURN
    SWITCH (
        TRUE (),
        _ship_status <> "Complete", 1,
        IF ( CALCULATE ( calc, 'Table (4)'[RefNumber] = _ref ) = _ship_date, 1, 0 )
    )

 

You can then add the measure as a filter to the visual and set the value to 1, please see the screenshot below (you do not need the measure in the table, you can just add it to the filter pane):

 

mark_endicott_0-1715944554539.png

 

If this works for you, please accept it as the solution. 

 

 

xifeng_L
Super User
Super User

Hi @Polar_A ,

 

If you want to add a new column to mark the data you need, then try the following expression.

 

xifeng_L_0-1715941726297.png

 

Column = 
VAR MaxShipDate = CALCULATE(MAX('Table'[ShippingDate]),ALLEXCEPT('Table','Table'[RefNumber]))
RETURN
IF('Table'[Shipping Status]="Complete" && 'Table'[ShippingDate]=MaxShipDate,1)

 

If you want to create a new table, then try the following table expression.

 

xifeng_L_1-1715941882392.png

 

Table 2 = 
FILTER(
    'Table',
    'Table'[Shipping Status]="Complete" &&
        'Table'[ShippingDate]=CALCULATE(MAX('Table'[ShippingDate]),ALLEXCEPT('Table','Table'[RefNumber]))
)

 

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

Hello @xifeng_L I am new to PowerBI, I have this Data table and I wanted get an output shown in the picture. There should be one category per workpack and the date will be just the latest date of the category.

Asrquareddd_11_0-1722994924103.png

 

 

Hi @Asrquareddd_11 , Your question is unrelated to the topic of this post. You can create a new post to describe your problem and provide sample data (not screenshots).

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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