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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
dushyant22j
Frequent Visitor

How to find Inactive User from two tables with many 2 many relationship in PowerBI

I want find Inactive Users(Eg. Retailers)

 

so what I try to do is find users present in retailers table which are not present in Transaction table with
date range and extra  filters as required ,

 

Source Tables in Power bi  :
Relationship between them are  :  Many to Many 

Retailer Table     
retaileridnamecountrycitycreated_Datedeviceid
1AIndiajaipur01-01-2020aa
2BIndiabanglore02-01-2020bb
3CIndiapune03-01-2020cc
3CIndiapune03-01-2020gg
4DIndiadelhi04-01-2020dd
5EIndiamumbai05-01-2020ee
5EIndiamumbai05-01-2020iij

 

Transactions   
retaileridtransactionidtransaction_datetransaciontype
11101-02-2020purchase
11201-02-2020purchase
21303-02-2020redemption
21404-02-2020signup
31505-02-2020purchase

 

 

Desired Output :

retaileridnamecountrycity
4DIndiadelhi
5EIndiamumbai

 

So how to find this ?    New Dax table ?  calculated columns ?  Calculated Measure >??

 

FYI : Just note if I want to do same thing in Database then its Equivalent SQL query in databse
( In database i have three tables Retailer , transaction , ledger  --- but when did modeling in power bi I merged (leder + Transaction) as one table and  keep Retailer table as it is.
 
select * from retailers
where retailers.id not in
(select ledger.retailerid from ledger
join transactions
on ledger.transactiond = transactions.id
where transactions.date between ("01-01-2020" and TODAY);

Please guide me through above ?

Extra question :  1)Does Many to Many relationship is ok to have in Power BI ?  Or Any disadvantages you guys can think of ? 

2) How to learn Dax from basics ? -- Any Document or Udemy Course recommanded for Dax ?? 

@need help , @dax Help , @need DAX Help

1 ACCEPTED SOLUTION

Hi  @dushyant22j ,

 

First create a calendar table as below:

Calendar = CALENDAR(MIN('Retailer Table'[created_Date]),TODAY())

Then create a measure as below:

Measure2 = 
var _table_transaction=CALCULATETABLE(VALUES(Transactions[retailerid]),FILTER(ALL('Transactions'),'Transactions'[transaction_date]>=MINX(ALLSELECTED('Calendar'),'Calendar'[Date])&&'Transactions'[transaction_date]<=MAXX(ALLSELECTED('Calendar'),'Calendar'[Date])))
Return
IF(MAX('Retailer Table'[retailerid]) IN _table_transaction,BLANK(),MAX('Retailer Table'[retailerid]))

And you will see:

Screenshot 2020-09-16 105514.png

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@dushyant22j , Use this measure with a common retail dimension .

or with a column from the Retailer table


M1 = calculate(count(Transactions[retailerid]))
M2 = calculate(count(retailerid[retailerid]))

if(not(isblank(M2)) && isblank([M1]), [M2], , blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak 
Hi ,
I tried as you mentioned 
created 3 measures and 1 calculated column just for reference.

M1 = CALCULATE(COUNT(Ledger_Transaction_Redemption[ledger.account_holder]))
M2 = CALCULATE(COUNT(Retailers[retailers.id]))
inactive = IF(NOT(ISBLANK([M2])) && ISBLANK([M1]),[M2],BLANK())
column - inactive Retailer = IF(NOT(ISBLANK([M2])) && ISBLANK([M1]),[M2],BLANK())

 

But when I tried to add filter based on transaction_date range , above dax (inactive)  give blank value.
So what should I do if I want to add date range filter ? Based on Transaction Date ? 

Example :  Transaction Date between 1st Jan,2020 and Today --  which users  are not in trasnaction table ?
                or  Transaction Date range  since last 3 months ,   which users entry not present in transaction table ? 
                            6 month --- etc ?? 

Could you please help ?


Thanks for reply.

But I am not getting it how to use them ?
Are you saying that  I have to create 3 Measures ?  or only 1 Measure ?
I tried to create 1 Measure but it show error as there two variable like M1 =  & M2 =

See below Image : 

dushyant22j_0-1599815335764.png

 



Could you please paste code here ?

@dushyant22j Chapter 6, Recipe 3 of DAX Cookbook has a Lost customer pattern. You can get the DAX here: https://github.com/gdeckler/DAXCookbook

 

If you are still having issues, @ me.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Thanks for reply.
I checked your pbix file and calculation for Lost Users.
But I am not understaning it how it will help to get list of Inactive users as per my requirement ?
 
Because in packt  , sturcture and relation beween tables are diffrent then my tables as shown in below image : 
Could you please Help  ?

dushyant22j_0-1600060556930.png

 

Hi  @dushyant22j ,

 

First create a calendar table as below:

Calendar = CALENDAR(MIN('Retailer Table'[created_Date]),TODAY())

Then create a measure as below:

Measure2 = 
var _table_transaction=CALCULATETABLE(VALUES(Transactions[retailerid]),FILTER(ALL('Transactions'),'Transactions'[transaction_date]>=MINX(ALLSELECTED('Calendar'),'Calendar'[Date])&&'Transactions'[transaction_date]<=MAXX(ALLSELECTED('Calendar'),'Calendar'[Date])))
Return
IF(MAX('Retailer Table'[retailerid]) IN _table_transaction,BLANK(),MAX('Retailer Table'[retailerid]))

And you will see:

Screenshot 2020-09-16 105514.png

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.