Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AmarBennour7
Regular Visitor

Detect if a customer is present last week

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.

AmarBennour7_0-1708425573792.png

client id

AmarBennour7_1-1708425605604.png

 

start & end date of the week

AmarBennour7_2-1708425651621.png

leak column

 

 

i've also uploaded a calendar table !

😞






1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @AmarBennour7 

 

Please try this:

First of all, I create a set of sample data:

vzhengdxumsft_0-1708499480480.png

Then add a calculate a column:

weeknum =
RANK (,, ORDERBY ( 'Table'[StartDate] ) )

vzhengdxumsft_1-1708499521741.png

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:

vzhengdxumsft_2-1708499605439.png

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.

View solution in original post

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @AmarBennour7 

 

Please try this:

First of all, I create a set of sample data:

vzhengdxumsft_0-1708499480480.png

Then add a calculate a column:

weeknum =
RANK (,, ORDERBY ( 'Table'[StartDate] ) )

vzhengdxumsft_1-1708499521741.png

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:

vzhengdxumsft_2-1708499605439.png

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.

lbendlin
Super User
Super User

Read about the EXCEPT and INTERSECT  commands in DAX.  They make this stuff very easy.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors