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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

DAX - Column content based on last Date slicer selection

Hello guys,

 

I'm trying to create a column in the fSales with the last status of the order according to the last selected date. I have a fact Sales, Calendar and a fact Historical Sales


fSales

id_ordersales date
ab12301/01/19
ab12402/01/19
ab12502/01/19
ab12603/01/19

fHistoricalSales

id_OrderDT_StatusStatus
ab12301/01/19NOR
ab12315/01/19CAN
ab12402/01/19NOR
ab12413/01/19CAN
ab12503/01/19NOR
ab12514/01/19CAN
ab12520/01/19REC
ab12603/01/19NOR

 

If I select the range 01/01/19 to 12/01/19 the .NewStatusOrder of ab124 should be NOR, but if I select to 13/01/19 it should be CAN.

 

I'm trying somithing like that, but it's not working:

.NewStatusOrder:= CALCULATE(
	 MAX(fHistorialSales[Status]) ;
 FILTER(
			ALLEXCEPT(fHistoricalSales;fHistorical[ID_ORDER]) ; 
				fHistoricalSales[DT_Status] = CALCULATE(MAX(fHistoricalSales[DT_Status]); 
							FILTER( fHistoricalSales; fHistorialSales[id_order] = EARLIER( fSales[ID_Order]) && fHistoricalSales[DT_Status] <= MAX(Date[DATE])))))
1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

1.PNG

 

NewStatusOrder =
VAR LatestDT_Status =
    CALCULATE (
        MAX ( fHistoricalSales[DT_Status] ),
        FILTER (
            ALLSELECTED ( fHistoricalSales ),
            fHistoricalSales[id_Order] = SELECTEDVALUE ( fHistoricalSales[id_Order] )
        )
    )
RETURN
    CALCULATE (
        SELECTEDVALUE ( fHistoricalSales[Status] ),
        FILTER ( fHistoricalSales, fHistoricalSales[DT_Status] = LatestDT_Status )
    )

3.PNG4.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
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

1.PNG

 

NewStatusOrder =
VAR LatestDT_Status =
    CALCULATE (
        MAX ( fHistoricalSales[DT_Status] ),
        FILTER (
            ALLSELECTED ( fHistoricalSales ),
            fHistoricalSales[id_Order] = SELECTEDVALUE ( fHistoricalSales[id_Order] )
        )
    )
RETURN
    CALCULATE (
        SELECTEDVALUE ( fHistoricalSales[Status] ),
        FILTER ( fHistoricalSales, fHistoricalSales[DT_Status] = LatestDT_Status )
    )

3.PNG4.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.
Anonymous
Not applicable

Hello @v-yulgu-msft , thanks for helping me.

 

The problem is that I have a 1 conection with Calendar[Date] and fSales[SalesDate] and a secondary connection with Calendar[Date] and fHistoricalSales[DT_Status]. Do you think using USERELATIONSHIP could help?

Hi @Anonymous ,

 

Make sure there existing an active relationship between fSales[id_order] and fHistoricalSales[id_Order], so, the relationships should be like below, above measure still works.

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.
ElenaN
Resolver V
Resolver V

Hello,

 

You can try this:

 

NewStatusOrder = 
VAR LastSelectedDate = LASTDATE(ALLSELECTED('Calendar'[Date]))
VAR LastOrderDate = CALCULATE(MAX(fHistoricalSales[DT_Status]), fHistoricalSales[DT_Status] <= LastSelectedDate)
RETURN
CALCULATE(MAX(fHistoricalSales[Status]), FILTER(fHistoricalSales, fHistoricalSales[DT_Status] = LastOrderDate))

Regards,

ElenaN

Anonymous
Not applicable

Hello @ElenaN , the LastSelectionDate is not getting the filter selection ;(

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.