cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaloniGupta
Helper I
Helper I

DAX formula for count of rows with multiple filters on columns from different tables

Hi,
I have a requirement where I need to display True/False for each SourceName, if Count of "order_id" column(coming from "Transaction" table) is > 0 then True else False, after filtering "TransactionYearMonth" from "Transaction" table in{"Jan-20","Feb-20","Mar-20"} and TransactionType'[Type]="Ticket"


Right now, it looks like this:

SaloniGupta_0-1618343880546.png

Correct Result:

SaloniGupta_1-1618343926946.png
How to add this filter?
FILTER('olap dim_TransactionType','olap dim_TransactionType'[Type]="Ticket")
in this calculated column

Flag =
var countorderid = COUNTX(
FILTER(RELATEDTABLE('olap fact_Transaction'),
'olap fact_Transaction'[TransactionYearMonth] in{"Jan-20","Feb-20","Mar-20"}),
[order_id])+0
RETURN
IF(countorderid>0,"True","False")
Also, I am trying to create this "Flag" calculation in the third table named "Client" which has the column "SourceName".
1 ACCEPTED SOLUTION
AllisonKennedy
Super User III
Super User III

@SaloniGupta  Which table is the calculated column in? Is there a relationship between type and transaction table? Looks like it's in the transaction table?? You may not need the RELATEDTABLE function.

 

Flag =
var countorderid = COUNTX(
FILTER(RELATEDTABLE('olap fact_Transaction'),
RELATED('olap dim_TransactionType'[Type]) ="Ticket" 
&& 
'olap fact_Transaction'[TransactionYearMonth] in{"Jan-20","Feb-20","Mar-20"}),
[order_id])+0
RETURN
IF(countorderid>0,"True","False")


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos. ?


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

View solution in original post

3 REPLIES 3
AllisonKennedy
Super User III
Super User III

@SaloniGupta  Which table is the calculated column in? Is there a relationship between type and transaction table? Looks like it's in the transaction table?? You may not need the RELATEDTABLE function.

 

Flag =
var countorderid = COUNTX(
FILTER(RELATEDTABLE('olap fact_Transaction'),
RELATED('olap dim_TransactionType'[Type]) ="Ticket" 
&& 
'olap fact_Transaction'[TransactionYearMonth] in{"Jan-20","Feb-20","Mar-20"}),
[order_id])+0
RETURN
IF(countorderid>0,"True","False")


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos. ?


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

View solution in original post

Hi @AllisonKennedy,
Thanks, this is giving the correct result and has resolved my issue.😊

@SaloniGupta  That's great to hear - please 'Accept as Solution' to mark the helpful post as a solution so others can find it easier and also know this post is solved. 



Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos. ?


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors