Forum Discussion
How can I dynamically add a row to a table
- 4 years ago
Hi Anonymous ,
For this you need to create a new table with the brands and the others line this can be achieve using the following syntax:
Brands + Others = UNION(Brands, DATATABLE ( "Brands", STRING, { { "Others" } } ) )Now add the following measure to you model:
Sales Selected Brands + Others = VAR SelectedSales = CALCULATE ( SUM(Sales[Dollars]), INTERSECT ( VALUES ( Brands[Brand]), VALUES ( 'Brands + Others'[Brand]) ) ) VAR UnSelectedSales = CALCULATE ( SUM(Sales[Dollars]), EXCEPT ( ALL ( Brands[Brand] ), VALUES ( Brands[Brand] ) ) ) VAR AllSales = CALCULATE ( SUM(Sales[Dollars]), ALL ( Brands[Brand]) ) RETURN IF ( HASONEVALUE ( 'Brands + Others'[Brand] ), SWITCH ( VALUES ( 'Brands + Others'[Brand]), "others", UnSelectedSales, SelectedSales ), AllSales )See result below and in attach file:
Hi Anonymous ,
For this you need to create a new table with the brands and the others line this can be achieve using the following syntax:
Brands + Others = UNION(Brands,
DATATABLE ( "Brands", STRING,
{ { "Others" } }
) )
Now add the following measure to you model:
Sales Selected Brands + Others =
VAR SelectedSales =
CALCULATE (
SUM(Sales[Dollars]),
INTERSECT (
VALUES ( Brands[Brand]),
VALUES ( 'Brands + Others'[Brand])
)
)
VAR UnSelectedSales =
CALCULATE (
SUM(Sales[Dollars]),
EXCEPT (
ALL ( Brands[Brand] ),
VALUES ( Brands[Brand] )
)
)
VAR AllSales =
CALCULATE (
SUM(Sales[Dollars]),
ALL ( Brands[Brand])
)
RETURN
IF (
HASONEVALUE ( 'Brands + Others'[Brand] ),
SWITCH (
VALUES ( 'Brands + Others'[Brand]),
"others", UnSelectedSales,
SelectedSales
),
AllSales
)
See result below and in attach file:
- Anonymous4 years agoNot applicable
Hi MFelix,
Thank you for the amazing answer, you just saved my life. I have a quick question, I want each of the bars in the visual to show the percentage of the total sales for the brand in that attribute. Something like the image below:
The orange bars should add up to 100% and the blue bars should add up to 100%. Could you please suggest changes in the measure to do so?
Thanks.
- MFelix4 years ago
Super User
Hi Anonymous ,
How is the formula you are using for the calculations?
- Anonymous4 years agoNot applicable
Hey MFelix,
Thanks I figured out the calculation myself.