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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Pinherio
Frequent Visitor

The difference between the earliest two dates

Hello, 

 

I have the table shown, I need a measure (1) that calculates the difference between the earliest two dates

and measure (2) how many times the price changed.

 

https://docs.google.com/spreadsheets/d/1yDRjc1srQRyoGOkXsubrSJfWDGLtP9U9/edit?usp=sharing&ouid=11016...

 

your help is highly appreciated.

 

Pinherio_0-1708768322656.png

@v-shex-msft 

@amitchandak 

2 ACCEPTED SOLUTIONS
ThxAlot
Super User
Super User

Simple enough,

Cnt = 
CALCULATE(
    COUNTROWS( 'PRICE' ),
    'PRICE'[#]
        <= MAXX(
            INDEX( 2, DISTINCT( 'PRICE' ), ORDERBY( 'PRICE'[Date], DESC ) ),
            'PRICE'[#]
        )
) - 1

ThxAlot_0-1708790285258.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1708818314814.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1708818314814.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ThxAlot
Super User
Super User

Simple enough,

Cnt = 
CALCULATE(
    COUNTROWS( 'PRICE' ),
    'PRICE'[#]
        <= MAXX(
            INDEX( 2, DISTINCT( 'PRICE' ), ORDERBY( 'PRICE'[Date], DESC ) ),
            'PRICE'[#]
        )
) - 1

ThxAlot_0-1708790285258.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looksl like but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1708775933673.pngJihwan_Kim_1-1708775944871.png

 

 

 

 

INDEX function (DAX) - DAX | Microsoft Learn

 

latest date value vs. second latest date value: =
VAR _t =
    FILTER (
        ALL ( 'Calendar'[Date] ),
        CALCULATE ( SUM ( Data[Price] ) ) <> BLANK ()
    )
VAR _latest =
    CALCULATE (
        SUM ( Data[Price] ),
        INDEX ( 1, _t, ORDERBY ( 'Calendar'[Date], DESC ) )
    )
VAR _second =
    CALCULATE (
        SUM ( Data[Price] ),
        INDEX ( 2, _t, ORDERBY ( 'Calendar'[Date], DESC ) )
    )
RETURN
    IF ( HASONEVALUE ( 'ID'[ID] ), _latest - _second )

 

OFFSET function (DAX) - DAX | Microsoft Learn

 

price change count: =
VAR _nonblankdate =
    FILTER (
        VALUES ( 'Calendar'[Date] ),
        CALCULATE ( SUM ( Data[Price] ) ) <> BLANK ()
    )
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( Data, 'Calendar'[Date] ),
            "@current", CALCULATE ( SUM ( Data[Price] ) ),
            "@prev",
                CALCULATE (
                    SUM ( Data[Price] ),
                    OFFSET ( -1, _nonblankdate, ORDERBY ( 'Calendar'[Date], ASC ) )
                )
        ),
        [@prev] <> BLANK ()
    )
RETURN
    IF (
        HASONEVALUE ( 'ID'[ID] ),
        COUNTROWS ( FILTER ( _t, [@current] <> [@prev] ) )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors