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
mhsk
Helper II
Helper II

Finding data based on closest to today calculation

Hi Team,

 

Its problaby sth you will answer on fly. Thanks for all contributions.

 

I have to find and show in a table just one row with closest to today data(mrp_qty and mrp_due_date) with category Purchase Order. i tried top n 1  and datediff, but no effects. Could you please advise how to go from whole table to table showing mi only what is marked yellow. I will use it dinamic so Today() will be needed.

Przechwytywanie.PNG

 

 

1 ACCEPTED SOLUTION

Hi @mhsk,

 

Please refer to below measures:

Next order =
CALCULATE (
    MIN ( 'Data Table'[date] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
            && 'Data Table'[date] >= TODAY ()
            && 'Data Table'[type] = "order"
    )
)

Qty of order =
CALCULATE (
    SUM ( 'Data Table'[qty] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[date] = [Next order]
            && 'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
    )
)

Next Demand =
CALCULATE (
    MIN ( 'Data Table'[date] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
            && 'Data Table'[date] >= TODAY ()
            && 'Data Table'[type] = "demand"
    )
)

Qty Demand =
CALCULATE (
    SUM ( 'Data Table'[qty] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[date] = [Next Demand]
            && 'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yulgu-msft
Employee
Employee

Hi @mhsk,

 

Please refer to below measures:

datediff =
ABS ( DATEDIFF ( SELECTEDVALUE ( Table3[mrp_due_date] ), TODAY (), DAY ) )

rank =
RANKX ( ALLSELECTED ( Table3 ), [datediff],, ASC, DENSE )

Add measure [rank] to "visual level filters" and set its value to 1.

1.PNG

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi , thanks for prompt reply

 

how to make it not using Visualisation filtering? (just dax that will return me 1 value (with measure) for closest date later than today and measure showing just 1 value that will be  mrp_qty closest to today but after today ?

 

thanks in advance

just to clarify i need to have table with just 1 row (for 1 part nr) with both NEXT (closest to today or today) ORDER  and NEXT (closest to today or today) DEMAND for each PART NUMBER.

 

my DATA TABLE looks more or less like this:

 

Today is 19.12.2018

 

part nrdatetypeqty
123417.12.2018order50
123421.12.2018order10
123431.12.2018order5
123419.12.2018demand1
123423.12.2018demand6
123430.12.2018 demand10

 

what i am looking for is:

part nrNext orderQty of orderNext DemandQty Demand
123421.12.20181019.12.20181

 

i cant get it with rank and visual level filters, is there a way to write it in dax?

Hi @mhsk,

 

Please refer to below measures:

Next order =
CALCULATE (
    MIN ( 'Data Table'[date] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
            && 'Data Table'[date] >= TODAY ()
            && 'Data Table'[type] = "order"
    )
)

Qty of order =
CALCULATE (
    SUM ( 'Data Table'[qty] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[date] = [Next order]
            && 'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
    )
)

Next Demand =
CALCULATE (
    MIN ( 'Data Table'[date] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
            && 'Data Table'[date] >= TODAY ()
            && 'Data Table'[type] = "demand"
    )
)

Qty Demand =
CALCULATE (
    SUM ( 'Data Table'[qty] ),
    FILTER (
        ALLSELECTED ( 'Data Table' ),
        'Data Table'[date] = [Next Demand]
            && 'Data Table'[part nr] = SELECTEDVALUE ( 'Data Table'[part nr] )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for you help, is there any simple way to recreate those 4 measures as calculated columns? (it would improve my performance)

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.