Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello,
I am working on a Power BI project to identify customers who fix their leaks. I receive a weekly file that I upload to SharePoint. I then use Power Query to compile the data and create a table listing customers with leaks for each week.
I am trying to create a calculated column or DAX formula (or a column) to check, for each customer and week, whether they had a leak in the previous week (S-1) and the current week (S) in a visualization table.
It's important to note that only customers with leaks are present in the file each week.
I've been trying to solve this problem, but I'm struggling to find a solution. If anyone has encountered a similar issue, I'm open to suggestions.
client id
start & end date of the week
leak column
i've also uploaded a calendar table !
😞
Solved! Go to Solution.
Please try this:
First of all, I create a set of sample data:
Then add a calculate a column:
weeknum =
RANK (,, ORDERBY ( 'Table'[StartDate] ) )
Then create a measure:
MEASURE =
VAR _newtable =
SUMMARIZE ( ALLSELECTED ( 'Table' ), 'Table'[weeknum], 'Table'[Leak] )
VAR _Currentweek =
MAX ( 'Table'[weeknum] )
RETURN
CONCATENATEX (
EXCEPT (
CALCULATETABLE (
VALUES ( 'Table'[Leak] ),
FILTER ( _newtable, 'Table'[weeknum] = _Currentweek - 1 )
),
CALCULATETABLE (
VALUES ( 'Table'[Leak] ),
FILTER ( _newtable, 'Table'[weeknum] = _Currentweek )
)
),
[Leak],
","
)
The result is as follow:
If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please try this:
First of all, I create a set of sample data:
Then add a calculate a column:
weeknum =
RANK (,, ORDERBY ( 'Table'[StartDate] ) )
Then create a measure:
MEASURE =
VAR _newtable =
SUMMARIZE ( ALLSELECTED ( 'Table' ), 'Table'[weeknum], 'Table'[Leak] )
VAR _Currentweek =
MAX ( 'Table'[weeknum] )
RETURN
CONCATENATEX (
EXCEPT (
CALCULATETABLE (
VALUES ( 'Table'[Leak] ),
FILTER ( _newtable, 'Table'[weeknum] = _Currentweek - 1 )
),
CALCULATETABLE (
VALUES ( 'Table'[Leak] ),
FILTER ( _newtable, 'Table'[weeknum] = _Currentweek )
)
),
[Leak],
","
)
The result is as follow:
If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Read about the EXCEPT and INTERSECT commands in DAX. They make this stuff very easy.