Forum Discussion

Ramps's avatar
Ramps
Helper I
8 years ago
Solved

Reporting by latest date

A Sales File has 4 fields Customer, Product, Quantity & Date.

I know how to list Customer, Product and Latest Date. That is easy.

Please explain how to produce a report using BI (not excel) of Customer, Product and Date where the date = the latest date for each customer.

There are several forum threads about latest date but none seem to explain this common type of query clearly.

 

Thank you

 

SALES FILE
CustomerProductQuantityDate
GillLaptop2811-Jan-18
GillRadio3105-Feb-18
GillPhone2510-Feb-18
JohnWashing Machine1916-Jan-18
JohnCar2526-Jan-18
JohnRadio3405-Feb-18
MaryTV2801-Jan-18
MaryKettle1611-Jan-18
MaryRadio1910-Feb-18
    
    
WANTED REPORT   
CustomerProductDate 
GillPhone10-Feb-18 
JohnRadio05-Feb-18 
MaryRadio10-Feb-18 
  • HI Ramps

     

    Sorry I was away for a while

     

    Another way could be to add a calculated column to identify the Last Date. Then you can filter by that

     

    LastDate =
    IF (
        TableName[Date]
            = CALCULATE (
                MAX ( TableName[Date] ),
                ALLEXCEPT ( TableName, TableName[Customer] )
            ),
        1
    )

7 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    HI Ramps

     

    Please try these MEASURES

     

    LatestDate = max(TableName[Date])
    Latest Product =
    VAR mydate = [LatestDate]
    RETURN
        CALCULATE (
            LASTNONBLANK ( TableName[Product], 1 ),
            FILTER (
                ALLEXCEPT ( TableName, TableName[Customer] ),
                TableName[Date] = mydate
            )
        )
      • Ramps's avatar
        Ramps
        Helper I

        Thank you Zubair_Muhammad for the quick reply.

        I have managed to replicate that OK. Thank you very much indeed !

        It seems a very complicated solution compared to other query languages.

        Do you or anyone else know simpler ways using Power BI please?

         

        I expected a very clear and straight forward filter feature with lots of common options like

        • where xxxxx = latest for zzzzz
        • where xxxxx = largest for zzzzz
        • “where date = latest date for customer”
        • or “where quantity = largest quantity for customer”
        • or “where date = latest date for product”

        The solution you suggested does work but is complicated.

        Presumably if the report needed the Customer, Product, Quantity, Date and other fields where the date = the latest date for each customer then a measure have to be added for each column like so:-

         

        LatestDate = max(Salesfile[Date])

         

        Latest Product =

        VAR mydate = [LatestDate]

        RETURN

            CALCULATE (

                LASTNONBLANK ( Salesfile[Product], 1 ),

                FILTER (

                    ALLEXCEPT ( Salesfile, Salesfile[Customer] ),

                    Salesfile[Date] = mydate

                )

            )

         

        Latest Quantity =

        VAR mydate = [LatestDate]

        RETURN

            CALCULATE (

                LASTNONBLANK ( Salesfile[Quantity], 1 ),

                FILTER (

                    ALLEXCEPT ( Salesfile, Salesfile[Customer] ),

                    Salesfile[Date] = mydate

                )

            )