Forum Discussion
Habres
2 years agoRegular Visitor
Subtracting two counts
Hi everyone! I have been trying for hours and searched for a solution, but I can't seem to get my dax code right. Maybe I not thinking in the right direction, because it does not seem so difficult...
- 2 years ago
Hi,
PBI file attached.
Hope this helps.
tharunkumarRTK
2 years agoSuper User
If you want to use naturalouterjoin then both the columns should have same data lineage otherwise it wil fail. One other option/workaround is to remove the lineage by writing the column as an expression and then the join will work.
for example, look the below pattern, &"" is added to the column names to remove the data lineage. Follow this pattern and then it should work
DEFINE
VAR StoresByCountry =
SELECTCOLUMNS (
TREATAS ( { "Armenia", "Australia", "Denmark" }, Store[CountryRegion] ),
"Country", Store[CountryRegion] & "",
"NumOfStores", CALCULATE ( COUNTROWS ( Store ) )
)
VAR CustomersByCountry =
SELECTCOLUMNS (
TREATAS ( { "Armenia", "Australia", "Denmark" }, Customer[CountryRegion] ),
"Country", Customer[CountryRegion] & "",
"NumOfCustomer", CALCULATE ( COUNTROWS ( Customer ) )
)
EVALUATE StoresByCountry
EVALUATE CustomersByCountry
EVALUATE
NATURALLEFTOUTERJOIN ( StoresByCountry, CustomersByCountry )
EVALUATE
NATURALLEFTOUTERJOIN ( CustomersByCountry, StoresByCountry )
EVALUATE
NATURALINNERJOIN ( StoresByCountry, CustomersByCountry )
Need Power BI consultation, hire me on UpWork .
If the post helps please give a thumbs up
If it solves your issue, please accept it as the solution to help the other members find it more quickly.
Tharun