Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I am struggling with a problem calculating average days in Power BI Desktop.
I have the following data in their own columns;
My aim is to find a formula/s which will help me calculate;
Does anyone know the steps, or formula's that i can use to calculate this information?
Thanks!
Solved! Go to Solution.
So in PowerBI there are 2 locations to create custom calculated columns:
I gave you the DAX version because it's easier to read/understand/manipulate IMO. With DAX, you don't need to reload your data everytime there is logic changed on a caluclated column. Instead, DAX uses your existing loaded dataset, and processes the logic. This makes is much more agile than SQL or PowerQuery. However, I still write native SQL queries to pull my data, and even build calculated columns in SQL. I tend to avoid PowerQuery if possible, though it has it's benefits like parsing JSON.
Going Forward:
This is fairly easy in DAX with a new calculated column.
PassedDays =
IF( [Status] = "Passed",
DATEDIFF([Created], [LastModified], SECOND) / 60 / 60 / 24,
BLANK()
)
// I intentionally do a datediff using seconds and divide because days rounds down and it's not an accurate representation.
// This means a DATEDIFF('2019-01-01 23:59','2019-01-02 00:01', DAY) = 1 Day even though it's 2 minutes.
Also, this MUST return BLANK() if not 'Passed' so the Non-Passed items don't get calculated in the average.
Thank you for the info, when I plugged in this formula to a custom column, I am recieving errors. Could you give me any pointers on what im doing wrong here? (see screenshots below)
Appreciate the help.
So in PowerBI there are 2 locations to create custom calculated columns:
I gave you the DAX version because it's easier to read/understand/manipulate IMO. With DAX, you don't need to reload your data everytime there is logic changed on a caluclated column. Instead, DAX uses your existing loaded dataset, and processes the logic. This makes is much more agile than SQL or PowerQuery. However, I still write native SQL queries to pull my data, and even build calculated columns in SQL. I tend to avoid PowerQuery if possible, though it has it's benefits like parsing JSON.
Going Forward:
Thanks for the explaination, this helps a lot!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
97 | |
65 | |
45 | |
39 | |
31 |
User | Count |
---|---|
164 | |
111 | |
61 | |
53 | |
38 |