Forum Discussion
SQL to DAX
- 8 years ago
HI Maghol
Please try this one
TEST = VAR TheDate = DATE ( 2018, 12, 5 ) RETURN SUMMARIZE ( Blad1, Blad1[order_id], "The_Qty", CALCULATE ( SUM ( Blad1[qty] ), TOPN ( 1, FILTER ( VALUES ( Blad1[log_date] ), Blad1[log_date] <= TheDate ), [log_date], DESC ) ) )
I have tried following DAX with the sample data in the attached Excel-file. Same error:
"A date column containing duplicate dates was specified in the call to function 'LASTDATE'. This is not supported."
TEST =
VAR TheDate = DATE ( 2018 , 1 , 5 )
RETURN
SUMMARIZE (
Blad1,
Blad1[order_id],
"The_Qty", CALCULATE (
SUM ( Blad1[qty] ),
LASTDATE (
FILTER (
VALUES ( Blad1[log_date] ),
Blad1[log_date] <= TheDate
)
)
)
)Example data here
HI Maghol
Please try this one
TEST =
VAR TheDate =
DATE ( 2018, 12, 5 )
RETURN
SUMMARIZE (
Blad1,
Blad1[order_id],
"The_Qty", CALCULATE (
SUM ( Blad1[qty] ),
TOPN (
1,
FILTER ( VALUES ( Blad1[log_date] ), Blad1[log_date] <= TheDate ),
[log_date], DESC
)
)
)- Maghol8 years agoFrequent Visitor
How can I change the static datevalue in the variable to a selected value from a slicer? Tried using the columnvalue directly, SELECTEDVALUE('slicer'), MAX(), ALLSELECTED(), IFHASONEVALUE() but the selected slicervalue isn't assigned to the variable.
Regards - Zubair_Muhammad8 years agoCommunity Champion
Hi Maghol
Unlike measures, calculated column and Calculated tables are computed during database processing(e.g. data refresh) and then stored in the model, so their calculation doesnot change when you select a slicer value
- Maghol8 years agoFrequent Visitor
Ok, thanks for the reply.
Is there a way to accomplish this? - Zubair_Muhammad8 years agoCommunity Champion