Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
hi,
Am using MS Analysis Server and need to calculate the number of days between yesterday and the due date. For yesterday i used the GetDate()-1 formula and i get a date like 2023-01-01 00:00:00:000 the due date looks similar. My script that calculates the number of days looks like this:
CASE WHEN TRY_CONVERT(DATE, CONVERT(VARCHAR(8), [DueDate]), 112) IS NULL OR TRY_CONVERT(DATE,CONVERT(VARCHAR(8), [CurrentDate]), 112) IS NULL
THEN 0
ELSE DATEDIFF(dd, TRY_CONVERT(DATE, CONVERT(VARCHAR(8), [DueDate]),112, TRY_CONVERT(DATE, CONVERT(VARCHAR(8), [CurrentDate],112))
END
now, the script is not working and gives an error message. Tried a lot of alternatives but nothing worked so far.
Anyone an idea what needs to be done???
Hi Mahesh, thanks for the swift response, unfortunately your suggestion gave issues as well. We are trying now "SWITCH(TRUE(), ISBLANK([DueDate]) || ISBLANK(TODAY()-1), 0, TRUE(), DATEDIFF([DueDate], TODAY()-1, DAY))"
the CurrentDate which is in fact GetDate()-1 seems to be the problem....
@Anonymous Please Try below script
CASE WHEN CONVERT(DATE,CONVERT(VARCHAR(20), [DueDate], 109),112) IS NULL OR CONVERT(DATE,CONVERT(VARCHAR(20), [CurrentDate], 109),112) IS NULL
THEN 0
ELSE DATEDIFF(dd, CONVERT(DATE,CONVERT(VARCHAR(20), [DueDate], 109),112), CONVERT(DATE,CONVERT(VARCHAR(20), [CurrentDate], 109),112))
END
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
8 |
User | Count |
---|---|
13 | |
12 | |
11 | |
10 | |
8 |