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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
jobf
Helper I
Helper I

Difference between application dates of products in a given location.

Hello. Please take a look at the table below:

Location  Period  Application  Date
P1  1st  1st application  01/01/2025
P1  2nd  1st application  01/02/2025
P1  1st  2nd application  01/20/2025
P1  2nd  2nd application  01/21/2025
P2  1st  1st application  01/05/2025
P2  2nd  1st application  01/06/2025
P2  1st  2nd application  01/15/2025
P2  2nd  2nd application  01/19/2025

 

I need a column or measure that shows the difference (days) between the current application of the period and the most recent date of the last application at a given location of the period. It would look something like this:

Location  Period  Application  DateDifference
P1  1st  1st application  01/01/2025 
P1  2nd  1st application  01/02/2025 
P1  1st  2nd application  01/20/202519
P1  2nd  2nd application  01/21/202519
P2  1st  1st application  01/05/2025 
P2  2nd  1st application  01/06/2025 
P2  1st  2nd application  01/15/202510
P2  2nd  2nd application  01/19/202513

 

If this is the first application, it should show a null value. One thing to keep in mind is that this table is just an example. Sometimes, there will be 12 or more applications in the same location.

2 ACCEPTED SOLUTIONS
Bibiano_Geraldo
Super User
Super User

Hi @jobf ,
you can achieve your goal by this DAX measure:

Difference = 
VAR CurrentDate = MAX('Table'[Date])
VAR CurrentApplication = SELECTEDVALUE('Table'[Application])
VAR Location = SELECTEDVALUE('Table'[Location])
VAR PreviousApplicationMaxDate =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Location] = Location &&
            'Table'[Application] <> CurrentApplication &&
            'Table'[Date] < CurrentDate
        )
    )
RETURN
IF(
    ISBLANK(PreviousApplicationMaxDate),
    BLANK(),
    DATEDIFF(PreviousApplicationMaxDate, CurrentDate, DAY)
)

 Your output will look like this:

Bibiano_Geraldo_0-1737483021120.png

 

View solution in original post

ThxAlot
Super User
Super User

Remember a rule of thumb, integer is the most preferrable data type in PBI, namely good for data compression and calculation as well. Turn columns Period and Application to integer.

 

ThxAlot_0-1737491899195.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

Remember a rule of thumb, integer is the most preferrable data type in PBI, namely good for data compression and calculation as well. Turn columns Period and Application to integer.

 

ThxAlot_0-1737491899195.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Bibiano_Geraldo
Super User
Super User

Hi @jobf ,
you can achieve your goal by this DAX measure:

Difference = 
VAR CurrentDate = MAX('Table'[Date])
VAR CurrentApplication = SELECTEDVALUE('Table'[Application])
VAR Location = SELECTEDVALUE('Table'[Location])
VAR PreviousApplicationMaxDate =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Location] = Location &&
            'Table'[Application] <> CurrentApplication &&
            'Table'[Date] < CurrentDate
        )
    )
RETURN
IF(
    ISBLANK(PreviousApplicationMaxDate),
    BLANK(),
    DATEDIFF(PreviousApplicationMaxDate, CurrentDate, DAY)
)

 Your output will look like this:

Bibiano_Geraldo_0-1737483021120.png

 

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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