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.
Could someone please help me in converting this working SQL Query to a DAX Query?
SELECT [ProductNumber],
CASE
WHEN @StartDate BETWEEN [StartDate] AND [EndDate] THEN @StartDate
WHEN @StartDate < [StartDate] THEN [StartDate]
END AS [StartDate],
CASE
WHEN @EndDate BETWEEN [StartDate] AND [EndDate] THEN @EndDate
WHEN @EndDate > [EndDate] THEN [EndDate]
END AS [EndDate],
[PromoCode],
[DaysAvailableInWeek]
FROM [#Promos]
WHERE [StartDate] <= @EndDate
AND [EndDate] >= @StartDate
ORDER BY 1;
DDL:
CREATE TABLE [#Promos] ([ProductNumber] INT, [StartDate] DATE, [EndDate] DATE, [PromoCode] VARCHAR(6), [DaysAvailableInWeek] VARCHAR(20) );
DML:
INSERT INTO [#Promos] ([ProductNumber], [StartDate], [EndDate], [PromoCode], [DaysAvailableInWeek]) VALUES (6512, '2020-01-11', '2020-01-13', 'ABC123', '1, 3, 5'); INSERT INTO [#Promos] ([ProductNumber], [StartDate], [EndDate], [PromoCode], [DaysAvailableInWeek]) VALUES(6514, '2020-01-12', '2020-01-14', 'ABC123', '4, 6'); INSERT INTO [#Promos] ([ProductNumber], [StartDate], [EndDate], [PromoCode], [DaysAvailableInWeek]) VALUES(2341, '2020-01-11', '2020-01-25', '321XYZ', '1, 2');
Here is what I tried so far, but it doesn't return correct results.
EVALUATE SUMMARIZECOLUMNS(
'Dim_Promos'[PromoCode],
'Dim_Product'[ProductNumber],
'Dim_Date_Start'[FullDate],
'Dim_Date_End'[FullDate],
FILTER('Dim_Date_Start', 'Dim_Date_Start'[FullDate] <= DATE(2020, 01, 15) ),
FILTER('Dim_Date_End', 'Dim_Date_End'[FullDate] >= DATE(2019, 04, 11) ),
"Days Available In Week", [Days Available In Week])
Also, I would need the date formatted as YYYY-MM-DD. When I tried the FORMAT function, it is throwing syntax error.
FORMAT('Dim_Date_Start'[FullDate], "YYYY-MM-DD"),
FORMAT('Dim_Date_End'[FullDate], "YYYY-MM-DD")
Thanks!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
26 | |
21 | |
16 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
19 | |
18 |