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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DAX QUERY FOR FILL DOWN

PBI QUERY.PNG

Hi Professionals..!!

 

Need help in understanding the dax for getting the last column data as measure, basically it is a fill down in dax.

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below and the attached pbix file.

Those are for both creating a measure and a calculated column.

 

Desired measure: = 
VAR currentrows =
    MAX ( Data[Rows] )
VAR currentdate =
    MAX ( Data[Date] )
VAR startdate =
    MINX (
        FILTER ( ALL ( Data ), Data[Rows] = currentrows && Data[NewMC] <> BLANK () ),
        Data[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            ALL ( Data ),
            Data[Rows] = currentrows
                && Data[Date] <= currentdate
                && Data[NewMC] <> BLANK ()
        ),
        Data[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( ALL ( Data ), Data[Rows] = currentrows && Data[Date] = previousdate ),
        Data[NewMC]
    )
RETURN
    IF (
        HASONEVALUE ( Data[Rows] ),
        IF ( MAX ( Data[Date] ) = startdate, SUM ( Data[NewMC] ), previousvalue )
    )

 

Desired CC = 
VAR currentrows = Data[Rows]
VAR currentdate = Data[Date]
VAR startdate =
    MINX (
        FILTER ( Data, Data[Rows] = currentrows && Data[NewMC] <> BLANK () ),
        Data[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            Data,
            Data[Rows] = currentrows
                && Data[Date] <= currentdate
                && Data[NewMC] <> BLANK ()
        ),
        Data[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( Data, Data[Rows] = currentrows && Data[Date] = previousdate ),
        Data[NewMC]
    )
RETURN
    IF ( Data[Date] = startdate, Data[NewMC], previousvalue )

 

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.

View solution in original post

Hi,

Your pbix file has a page-filter.

Please try the below and check the attached file.

 

Mydesire = 
VAR currentrows =
    MAX ( Mydata[Rows] )
VAR currentdate =
    MAX ( Mydata[Date] )
VAR startdate =
    MINX (
        FILTER ( ALLSELECTED( Mydata ), Mydata[Rows] = currentrows && Mydata[NewMC] <> BLANK () ),
        Mydata[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            ALLSELECTED ( Mydata ),
            Mydata[Rows] = currentrows
                && Mydata[Date] <= currentdate
                && Mydata[NewMC] <> BLANK ()
        ),
        Mydata[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( ALLSELECTED ( Mydata ), Mydata[Rows] = currentrows && Mydata[Date] = previousdate ),
        Mydata[NewMC]
    )
RETURN
    IF (
        HASONEVALUE ( Mydata[Rows] ),
        IF ( MAX ( Mydata[Date] ) = startdate, SUM ( Mydata[NewMC] ), previousvalue )
    )

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.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

https://drive.google.com/file/d/1CMFr0oRjq1rb8gdCas-5V5oEa_s606uW/view 

@Jihwan_Kim please help us with this data as we are unable to get the correct result


Hi,

Your pbix file has a page-filter.

Please try the below and check the attached file.

 

Mydesire = 
VAR currentrows =
    MAX ( Mydata[Rows] )
VAR currentdate =
    MAX ( Mydata[Date] )
VAR startdate =
    MINX (
        FILTER ( ALLSELECTED( Mydata ), Mydata[Rows] = currentrows && Mydata[NewMC] <> BLANK () ),
        Mydata[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            ALLSELECTED ( Mydata ),
            Mydata[Rows] = currentrows
                && Mydata[Date] <= currentdate
                && Mydata[NewMC] <> BLANK ()
        ),
        Mydata[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( ALLSELECTED ( Mydata ), Mydata[Rows] = currentrows && Mydata[Date] = previousdate ),
        Mydata[NewMC]
    )
RETURN
    IF (
        HASONEVALUE ( Mydata[Rows] ),
        IF ( MAX ( Mydata[Date] ) = startdate, SUM ( Mydata[NewMC] ), previousvalue )
    )

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.

Anonymous
Not applicable

Jihwan_Kim
Super User
Super User

Hi,

Please check the below and the attached pbix file.

Those are for both creating a measure and a calculated column.

 

Desired measure: = 
VAR currentrows =
    MAX ( Data[Rows] )
VAR currentdate =
    MAX ( Data[Date] )
VAR startdate =
    MINX (
        FILTER ( ALL ( Data ), Data[Rows] = currentrows && Data[NewMC] <> BLANK () ),
        Data[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            ALL ( Data ),
            Data[Rows] = currentrows
                && Data[Date] <= currentdate
                && Data[NewMC] <> BLANK ()
        ),
        Data[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( ALL ( Data ), Data[Rows] = currentrows && Data[Date] = previousdate ),
        Data[NewMC]
    )
RETURN
    IF (
        HASONEVALUE ( Data[Rows] ),
        IF ( MAX ( Data[Date] ) = startdate, SUM ( Data[NewMC] ), previousvalue )
    )

 

Desired CC = 
VAR currentrows = Data[Rows]
VAR currentdate = Data[Date]
VAR startdate =
    MINX (
        FILTER ( Data, Data[Rows] = currentrows && Data[NewMC] <> BLANK () ),
        Data[Date]
    )
VAR previousdate =
    MAXX (
        FILTER (
            Data,
            Data[Rows] = currentrows
                && Data[Date] <= currentdate
                && Data[NewMC] <> BLANK ()
        ),
        Data[Date]
    )
VAR previousvalue =
    MAXX (
        FILTER ( Data, Data[Rows] = currentrows && Data[Date] = previousdate ),
        Data[NewMC]
    )
RETURN
    IF ( Data[Date] = startdate, Data[NewMC], previousvalue )

 

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.