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
Pinherio
Regular 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.


Go to My LinkedIn Page


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.