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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Employee
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
Employee
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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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