I have Data like this and I want to create a matrix visual. Since I need the Amount and Percentage in one column inside the matrix, I have created the following structured table in Power BI:
Description
Value
Sales Amount
50000
Sales Percentage
12%
Sales Amount
25000
Sales Percentage
25%
Sales Amount
75000
Sales Percentage
64%
Since it's not possible to store different format types in a single column in Power BI the percentage is stored as decimals and I created a measure to change the format based on the description column with the following code:
Value_formated =
VAR Val = SUM ( Table[Value] )
RETURN
SWITCH (
SELECTEDVALUE ( 'Table'[Description] ),
"Sales Amount", FORMAT ( Val, "0" ),
"Sales Percentage", FORMAT ( Val, "0.00%" ))
My question is how am I able to create a conditional formating to change the underlying color based on the percentage Value? Like for example if the percentage is negative, the percentage field should be red and if positive green. But since percentage is mixed with total number, how can I only filter the percentages? I have tried the following guide: https://xyloslearning.com/en/power-bi-using-a-measure-to-set-up-conditional-formatting/ but I couldn't select the coloring measure maybe because there are two different formats? Can anybody help me?
Thanks!
Create a format measure as follows:
Format =
VAR v = MIN ( 'Table'[Value] )
VAR d = MIN ( 'Table'[Description] )
RETURN
SWITCH(TRUE(),
d = "Sales Percentage" && v < 0, 0,
d = "Sales Percentage" && v >= 0, 1,
2)
Apply conditional formatting as follows:
Related
I have a summary table in Power BI which shows how many days it takes for leads to convert to a sale. It has 2 columns, sum_convert (the amount of days in between lead creation date and converted date) and count_lead (the count of leads that have taken that amount of days to convert), both are numeric values. Here is an example of the data:
What I want, is a column next to count_lead that shows the running percentage total in the specific ascending order of sum_convert. Currently I've created a measure called lead_count which is the sum of count_lead. Then I've attempted to create the cumulative total with the following measure:
Cum_Lead = calculate([lead_count], FILTER(ALL(Convert_Count_Summary[Sum_Convert]), SUM(Convert_Count_Summary[count_lead]) <= [lead_count]))
This creates a cumulative total, but not in the specific sum_convert order, it's in the order of largest volume for count_lead. Any idea what I need to change so that it's in the order of sum_convert?
You could do this in Power Query using M:
= Table.AddColumn(#"Previous Step", "Cumulative_Count_PQ", each List.Sum(List.FirstN(#"Previous Step"[count_lead],_[sum_convert]+1)), type number)
Or as a calculated column using DAX:
Cumulative Count DAX =
CALCULATE (
SUM ( Convert_Count_Summary[count_lead] ),
ALL ( Convert_Count_Summary ),
Convert_Count_Summary[sum_convert] <= EARLIER ( Convert_Count_Summary[sum_convert] )
)
Edit:
Cumulative percentages in Power Query:
= Table.AddColumn(#"Previous Step", "Cumulative_Count_Percent_PQ", each List.Sum(List.FirstN(#"Previous Step"[count_lead],_[sum_convert]+1)) / List.Sum(#"Previous Step"[count_lead]), Percentage.Type)
Cumulative percentages calculated column in DAX:
Cumulative Count % DAX =
VAR _Numerator =
CALCULATE (
SUM ( Convert_Count_Summary[count_lead] ),
ALL ( Convert_Count_Summary ),
Convert_Count_Summary[sum_convert] <= EARLIER ( Convert_Count_Summary[sum_convert] )
)
VAR _Divisor =
SUM ( Convert_Count_Summary[count_lead] )
RETURN
DIVIDE (
_Numerator,
_Divisor
)
I have SKUs data with some financial information. I have grouped the SKUs in 4 categories using a measure with SWITCH. Now I would like to summarise the information (e.g. total revenues of the products in each category) but I cannot get the summary to add up to the correct value.
Data model:
FactTable: fact table containing financial information (product code, revenue, profit, period, etc.)
DimSKU: mapping table with SKUs data (product code, brand, segment, etc.)
DimDates: date table (period, months, etc.)
Creating 4 product categories:
(using a measure and not a calculated column as the users can use a dropdown list and select different periods)
My Quadrants =
VAR
Quadrants =
SWITCH(
TRUE(),
AND([SKU_profit] >= [Total_profit], [SKU_growth] >= [Total_growth]), "Maintain",
AND([SKU_profit] < [Total_profit], [SKU_growth] < [Total_growth]), "Address",
AND([SKU_profit] >= [Total_profit], [SKU_growth] < [Total_growth]), "Grow",
AND([SKU_profit] < [Total_profit], [SKU_growth] >= [Total_growth]), "Investigate"
)
RETURN
Quadrants
Calculating YTD sales:
YTD revenue =
VAR
YTD_revenue = TOTALYTD(SUM(FactTable[Revenue]), DimDates[Date])
RETURN
YTD_revenue
Summarising data:
I can add the measure to a visual like a table and it works perfectly fine as long as I also display all the SKUs. Ideally, I would like a summary like the following:
MyQuadrants / Revenue
Maintain / 1,000
Address / 250
Grow / 500
Investigate / 350
I would be grateful if anyone could point me in the right direction.
Thanks all.
Edit
I have managed to make it work thanks to David's suggestion. See below for reference.
Creating configuration table
ConfigTable =
VAR
Total_profit = [Total_profit]
VAR
Total_growth = [Total_growth]
RETURN
{
("Maintain", Total_profit, 1, Total_growth, 1),
("Address", 0, Total_profit, 0, Total_growth),
("Grow", Total_profit, 1, 0, Total_growth),
("Investigate", 0, Total_profit, Total_growth, 1)
}
// 5 columns: quadrant, min profit, max profit, min growth, max growth
// Use table constructor to use variables
Creating measure
YTD revenue (segmented) =
CALCULATE(
[YTD revenue],
FILTER(
VALUES(DimSKU),
NOT ISEMPTY(
FILTER(
ConfigTable,
(
[SKU_profit] >= ConfigTable[min profit] &&
[SKU_profit] < ConfigTable[max profit] &&
[SKU_growth] >= ConfigTable[min growth] &&
[SKU_growth] < ConfigTable[min growth]
)
)
)
)
I have table with Sales. All Sales divide between Men and Women. I need to find out who have the biggest count of sales, men or woman.
I have tried using Summarize and MAXX together, but sonething is wrong.
MAXX(SUMMARIZE(
'public Brand',
'public Brand'[Возрастная группа],
"Свод",
COUNT('public Brand'[Id]))
If I understand your requirement correct, you need a single output "Men" OR "Women" based on the count sales count/amount. For example, if there are total 10 count or row for Men and 12 for Women, you need Women as output from the measure. I prepared a very simple data set for example (Excel part in the image) to calculate the measure. You can see the final output in the red marked box.
Here below is the Measure Code-
For most number of sales number
Gender With Most Count =
VAR Gourp_by_gender_with_count =
SUMMARIZE(
Sales,
Sales[Gender],
"GenderCount", COUNT(Sales[Gender])
)
VAR max_count_among_gender_group =
MAXX (
TOPN(1,Gourp_by_gender_with_count,[GenderCount],DESC),
[Gender]
)
RETURN max_count_among_gender_group
For most number of sales amount
Gender With Most Sales Amount =
VAR Gourp_by_gender_with_amount =
SUMMARIZE(
Sales,
Sales[Gender],
"GenderWiseSales", SUM(Sales[Amount])
)
VAR max_amount_among_gender_group =
MAXX (
TOPN(1,Gourp_by_gender_with_amount,[GenderWiseSales],DESC),
[Gender]
)
RETURN max_amount_among_gender_group
I want to create a measure (Average Late) in powerBI that calculates the Maximum of Late per Ordernumber, sum them up & divide the by the number of orders.
enter image description here
I also want this measure to be dynamic and only calculate whats displayed with filters.
enter image description here
I have tried with functions such as CALCULATE, MAX, DISTINCT & SUM.
Try this:
Measure =
VAR distinct_ordernumber =
DISTINCTCOUNT ( 'Table'[OrderNumber] )
VAR sum_max_late_per_ordernumber =
SUMX (
SUMMARIZE ( 'Table'; 'Table'[OrderNumber]; "max_late"; MAX ( 'Table'[Late] ) );
[max_late]
)
RETURN
FORMAT ( sum_max_late_per_ordernumber / distinct_ordernumber; "##.00" )
I'm trying to create a matrix in a Power BI report summarizing Salesperson performance sliced in a number of different ways.
I know how to create a matrix with Rows - Salesperson, Columns - Product Type, and Values - count of Sales which will show the number of Sales per Salesperson per Product Type, but I'd like also be able to do the following:
Add an additional column set to pivot on (e.g. Sales Year), so that I could see count of Sales pivoted by both Product Type and Year in the same table side by side (i.e., not nested).
Add additional summary columns to my matrix showing values such as average Sale Amount by Salesperson, % of total number of Sales by Salesperson.
For clarity, I'd imagine that this would result in a matrix where the column headers read: Salesperson, Product 1, Product 2, ..., Year 1, Year 2, ..., Total Sales Count, Average Sales Amount, % of Total Sales Count. See image link below (I don't have the reputation points to include the actual image yet)
I recognize that I can do this by creating measures which effectively replicate how the matrix is splitting out the values and adding each measure as a value (no Columns), but I don't want to have to create new measures and update the matrix every year or every time we add a new Product Type.
I've also looked at custom visuals on the Power BI marketplace, but didn't see any that would achieve this.
It's possible to do this, but not super easy. You'll need a measure with a SWITCH as well as a table for your headers.
You can create a header table along these lines:
Header =
UNION (
SUMMARIZE ( Sales, Sales[Product], "Group", "By Product", "Index", 1 ),
SUMMARIZE ( Sales, Sales[Year], "Group", "By Year", "Index", 2 ),
DATATABLE (
"Header", STRING,
"Group", STRING,
"Index", INTEGER,
{
{ " Total", "Summarizations", 3 },
{ "% of Total Sales", "Summarizations", 3 },
{ "Avg Sale Size", "Summarizations", 3 }
}
)
)
Which will look like this:
Header, Group, Index,
Product 1, By Product, 1,
Product 2, By Product, 1,
2016, By Year, 2,
2017, By Year, 2,
2018, By Year, 2,
Total, Summarizations, 3,
% of Total Sales, Summarizations, 3,
Avg Sale Size, Summarizations, 3
This table will automatically expand when more products or years are added.
(Note: The Index column is so I can order them properly using Sort by Column.)
Once you have that, you just need to put Group and Header on the columns of a matrix visual and Salesperson on the rows, with a switching measure in the values.
Measure =
VAR Val =
SWITCH (
SELECTEDVALUE ( Header[Group] ),
"By Product", CALCULATE (
SUM ( Sales[Amount] ),
FILTER ( Sales, Sales[Product] = MAX ( Header[Header] ) )
),
"By Year", CALCULATE (
SUM ( Sales[Amount] ),
FILTER ( Sales, Sales[Year] = VALUE ( MAX ( Header[Header] ) ) )
),
SWITCH (
SELECTEDVALUE ( Header[Header] ),
"% of Total Sales", DIVIDE (
SUM ( Sales[Amount] ),
CALCULATE ( SUM ( Sales[Amount] ), ALL ( Sales ) )
),
"Avg Sale Size", AVERAGE ( Sales[Amount] ),
SUM ( Sales[Amount] )
)
)
RETURN
IF (
SELECTEDVALUE ( Header[Header] ) = "% of Total Sales",
FORMAT ( Val, "0.0%" ),
FORMAT ( Val, "0.0" )
)
Each different group gets its own calculation and we have to use the FORMAT function to force the table to format the percentage function properly.
(Note: If you have slicers or filtering, you probably want to use ALLSELECTED where I used ALL above.)
Here's what my table looks like (not the exact same data but similar structure)
and here's the PBIX file I created for this:
https://drive.google.com/file/d/1qxc5p53MgmOm-NH3EcivkZLhLeEHpr4R/