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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
arlequin71
Helper II
Helper II

How i can define a Dax to summarize True resultant values from another DAX in a Matrix?

Hello, i´m looking for a Dax to summarize the highlighted Totals in the attached Matrix image (by Region AN).

1 Value is result of the following DAX (AN Region's example):

 

AN by Category =
Var ANinCat = CALCULATE(DISTINCTCOUNT(dim_country[Region]),FILTER(dim_Country,dim_country[Region]="AN"),FILTER(ft_Sales,ft_sales[Sales]<>BLANK()))
Var CatinAN =
CALCULATE(COUNTROWS(DISTINCT(dim_customers[Category])),
FILTER(dim_Country,dim_country[Region]="AN"),FILTER(ft_Sales,ft_Sales[Sales]<>BLANK()),ALLEXCEPT(dim_Country,dim_country[Region]), ALLEXCEPT(ft_Sales,ft_Sales[Sales]))
RETURN
IF(ISINSCOPE(dim_customers[Category]),ANinCat,CatinAN)
 
Ctgry in AN =
CALCULATE(COUNTROWS(DISTINCT(dim_customers[Category])),
FILTER(dim_Country,dim_country[Region]="AN"),FILTER(ft_sales,ft_sales[Sales]<>BLANK()))
 

arlequin71_0-1624124665504.png

The second part of IsInscope is the one i need to fix (var CatinAn) in order to reflect the right total value.  '2' in this case.

These are the scripts to recreate the example's tables:

 

dim_customers

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUXJOLElNzy+qVHBUitUBixoiizrBRI2QRZ1hosbIoi4wURNkUVel2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer_ID = _t, Category = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer_ID", Int64.Type}, {"Category", type text}})
in
#"Changed Type"

 

ft_sales

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc6xDcAwCATAXahdPBgnziyW918jQSjhixTI6PSA1xKVlgXgeUwhuyWP5Gg7iintxEZLiI9aYqP4TI6hz2Zaj3uzohex4S+tlPZkf7+xbw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProductID = _t, CountryId = _t, Customer_ID = _t, Sales = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CountryId", Int64.Type}, {"Customer_ID", Int64.Type}, {"Sales", Int64.Type}})
in
#"Changed Type"

 

dim_country

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOyMxJBdLB/s7+SrE60UpGQI5jUXpqXklmXiKyhDGQE1pUml6aWIksbALk+KZWZCbngxgRYDFTIDMgsSgRqtbRDyxqBmQ65edklmUmIgTNgUzX5NLElPwihKAFyGH5Ofm5SchKLUGmphaVQkViAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Country ID" = _t, Country = _t, Region = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Country ID", Int64.Type}, {"Country", type text}, {"Region", type text}})
in
#"Changed Type"

 

dim_product

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYUel2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProductID = _t, Division = _t, BusinessUnit = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ProductID", Int64.Type}, {"Division", type text}, {"BusinessUnit", type text}})
in
#"Changed Type"

 

Datamodel

arlequin71_1-1624125262214.png

 

I really appreciate any help.  Regards.

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

Hi  @arlequin71 ,

This function is used to modify Total.

Ctgry in AN_Hasonevalue =
var _table=SUMMARIZE('dim_customers',[Category],"1",[Ctgry in AN])
return
IF(HASONEVALUE(dim_customers[Category]),[Ctgry in AN],SUMX(_table,[1]))

Create a virtual table by SUMMARIZE, and judge by HASONEVALUE. If there is a value, it will display [Ctgry in AN], and if there is no value, it will display the correct Total.

 

For example, I should display Total as 4 here, but the display is all 1:

vyangliumsft_0-1624613240590.png

After using the function, Total will display the correct value:

vyangliumsft_1-1624613240592.png

 

Incorrect Total is a common problem, this article explains why and how to solve it:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 

Best Regards,

Liu Yang

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

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @arlequin71 ,

This function is used to modify Total.

Ctgry in AN_Hasonevalue =
var _table=SUMMARIZE('dim_customers',[Category],"1",[Ctgry in AN])
return
IF(HASONEVALUE(dim_customers[Category]),[Ctgry in AN],SUMX(_table,[1]))

Create a virtual table by SUMMARIZE, and judge by HASONEVALUE. If there is a value, it will display [Ctgry in AN], and if there is no value, it will display the correct Total.

 

For example, I should display Total as 4 here, but the display is all 1:

vyangliumsft_0-1624613240590.png

After using the function, Total will display the correct value:

vyangliumsft_1-1624613240592.png

 

Incorrect Total is a common problem, this article explains why and how to solve it:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

v-yangliu-msft
Community Support
Community Support

Hi  @arlequin71 ,

You can use hasonevaluation to display the value in total.

Here are the steps you can follow:

1. Create measure.

Ctgry in AN_Hasonevalue =
var _table=SUMMARIZE('dim_customers',[Category],"1",[Ctgry in AN])
return
IF(HASONEVALUE(dim_customers[Category]),[Ctgry in AN],SUMX(_table,[1]))

2. Result:

vyangliumsft_0-1624262498235.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Liu, thanks for your answer, your approach is closer to the solution i require but what specifically need is to fix the first column Total.  In my example it is showing 4 instead 2 which is the right result.

 

Thanks for your help.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.