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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Syndicate_Admin
Administrator
Administrator

¿Cómo puedo definir un Dax para resumir los valores verdaderos resultantes de otro DAX en una matriz?

Hola, estoy buscando un Dax para resumir los totales resaltados en la imagen de matriz adjunta (por región AN).

1 El valor es el resultado del siguiente DAX (ejemplo de una región):

AN por Categoría =
Var ANinCat = CALCULATE(DISTINCTCOUNT(dim_country[Region]),FILTER(dim_Country,dim_country[Region]="AN"),FILTER(ft_Sales,ft_sales[Sales]<>BLANK()))
Donde CatinAN =
CALCULATE(COUNTROWS(DISTINCT(dim_customers[Categoría])),
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]))
devolución
IF(ISINSCOPE(dim_customers[Categoría]),ANinCat,CatinAN)
Ctgry en AN =
CALCULATE(COUNTROWS(DISTINCT(dim_customers[Categoría])),
FILTER(dim_Country,dim_country[Region]="AN"),FILTER(ft_sales,ft_sales[Sales]<>BLANK()))

arlequin71_0-1624124665504.png

La segunda parte de IsInscope es la que necesito arreglar (var CatinAn) para reflejar el valor total correcto. '2' en este caso.

Estos son los scripts para volver a crear las tablas del ejemplo:

dim_customers

dejar
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]),
#"Tipo cambiado" = Table.TransformColumnTypes(Source,{{"Customer_ID", Int64.Type}, {"Category", escriba text}})
en
#"Tipo cambiado"

ft_sales

dejar
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]),
#"Tipo cambiado" = Table.TransformColumnTypes(Source,{{"CountryId", Int64.Type}, {"Customer_ID", Int64.Type}, {"Sales", Int64.Type}})
en
#"Tipo cambiado"

dim_country

dejar
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]),
#"Tipo cambiado" = Table.TransformColumnTypes(Source,{{"Country ID", Int64.Type}, {"Country", type text}, {"Region", type text}})
en
#"Tipo cambiado"

dim_product

dejar
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]),
#"Tipo cambiado" = Table.TransformColumnTypes(Source,{{"ProductID", Int64.Type}, {"Division", type text}, {"BusinessUnit", type text}})
en
#"Tipo cambiado"

Modelo de datos

arlequin71_1-1624125262214.png

Realmente aprecio cualquier ayuda. saludos.

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Hay @arlequin71 ,

Esta función se utiliza para modificar 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]))

Cree una tabla virtual por SUMMARIZE y juzgue por HASONEVALUE. Si hay un valor, mostrará [Ctgry en AN], y si no hay ningún valor, mostrará el Total correcto.

Por ejemplo, debería mostrar Total como 4 aquí, pero la pantalla es todo 1:

vyangliumsft_0-1624613240590.png

Después de usar la función, Total mostrará el valor correcto:

vyangliumsft_1-1624613240592.png

Total incorrecto es un problema común, este artículo explica por qué y cómo resolverlo:

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

Saludos

Liu Yang

Si este post ayuda,entonces por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

View solution in original post

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Hay @arlequin71 ,

Esta función se utiliza para modificar 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]))

Cree una tabla virtual por SUMMARIZE y juzgue por HASONEVALUE. Si hay un valor, mostrará [Ctgry en AN], y si no hay ningún valor, mostrará el Total correcto.

Por ejemplo, debería mostrar Total como 4 aquí, pero la pantalla es todo 1:

vyangliumsft_0-1624613240590.png

Después de usar la función, Total mostrará el valor correcto:

vyangliumsft_1-1624613240592.png

Total incorrecto es un problema común, este artículo explica por qué y cómo resolverlo:

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

Saludos

Liu Yang

Si este post ayuda,entonces por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Syndicate_Admin
Administrator
Administrator

Hay @arlequin71 ,

Puede utilizar hasonevaluation para visualizar el valor en total.

Estos son los pasos que puede seguir:

1. Crear medida.

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. Resultado:

vyangliumsft_0-1624262498235.png

Saludos

Liu Yang

Si este post ayuda,entonces por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Hola Liu, gracias por su respuesta, su enfoque está más cerca de la solución que necesito, pero lo que necesita específicamente es corregir la primera columna Total. En mi ejemplo está mostrando 4 en lugar de 2 que es el resultado correcto.

Gracias por su ayuda.

Syndicate_Admin
Administrator
Administrator

Este parece ser el enfoque correcto

(1) Dax para Power BI: corrección de totales de medida incorrectos - YouTube

pero cuando intento aplicar la fórmula recibo el mensaje:

La expresión hace referencia a varias columnas. Varias columnas no se pueden convertir en un valor escalar.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.