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
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 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:
Hello community and DAX gurus!
I am trying to create a measure that calculates the total product sales for a specfic month only for does products that has been sold the same period last year.
Below is an illustration of what I want to achieve:
The first thing I did was to create a measure to calculate the Sales Amount for previous year:
Sales Amount PY =
CALCULATE(
[Sales Amount],
SAMEPERIODLASTYEAR(DimDate[Datekey])
)
The second thing I did was to create a Comparable range flag as measure:
ComparableRange = IF(FactSales[Sales Amount] = BLANK() || FactSales[Sales Amount PY] = BLANK(),0,1)
Third step I created a measure to calculate the total product sales:
Total Product Sales =
CALCULATE(
FactSales[Sales Amount],ALL(DimProduct)
)
The final step I want to calculate the total product sales only for does products being comparable.
I tried this solution but not getting it to work, it is only returning blank:
Total Product Sales Comparable =
var CompRangeTable = ADDCOLUMNS(FactSales,"#CompRange",[ComparableRange])
var FilteredTable = FILTER(CompRangeTable,[#CompRange] = 1)
return
CALCULATE(FactSales[Sales Amount],ALL(DimProduct),FilteredTable)
I also tried this solution but still getting blanks:
Total Product Sales Comparable =
var FilteredTable = FILTER(FactSales, [Sales Amount PY]*[Sales Amount]+0<>0)
return
CALCULATE([Sales Amount],ALL(DimProduct),FilteredTable)
I wonder if the issue is that the Comparable range flag doesn't evaluate during context in the measure and potentially only returning 0 and if that is the case how would you go about to solve this problem.
To demonstrate my problem I have used the ContosoRetailDW sample database with a simple star scheme consisting in the tables "FactSales", "DimDate" and "DimProduct"
This expression
ADDCOLUMNS(FactSales,"#CompRange",[ComparableRange])
is equal to
CALCULATETABLE(
ADDCOLUMNS(FactSales,"#CompRange",[ComparableRange])
,Calendar[CalendarMonth]=2000805
,DimProduct[Brand]="The Phone Company"
)
so :
1 - FactSales is cutted by context
2 - ADDCOLUMNS applies a row context to [ComparableRange] measure
to EACH row.
For example you have a row with FactSales[date]="01/01/2022"; FactSales[product]="iPhone"; FactSales[customer]="Bill Gates" ; FactSales[price]=200 ; FactSales[qty]=10 Your [Sales Amount PY] in [ComparableRange] will search SAMEPERIODLASTYEAR() on a day level, for the sample it is - "01/01/2021" most probably you have no sales for customer "Bill Gates" that date, so [ComparableRange] will return you - 0
Try this one, it's not optimized, so just check if it works.
Total Product Sales Comparable=
VAR CurrentCalendarMonth = SELECTEDVALUE(Calendar[CalendarMonth])
VAR allProducts =
CALCULATETABLE(
VALUES(DimProduct[ProductName])
,ALL() -- remove all filters and crossffilters from your data model
)
VAR totalSalesAndCompRng =
ADDCOLUMNS(
allProducts
,"#totalAmount
,CALCULATE(
[Sales Amount]
,Calendar[CalendarMonth] = CurrentCalendarMonth
)
,"#CompRange"
,CALCULATE(
[ComparableRange]
,Calendar[CalendarMonth] = CurrentCalendarMonth
)
)
VAR onlyCompRng =
FILTER(
totalSalesAndCompRng
,[#CompRange]=1
)
RETURN
SUMX(onlyCompRng,[#CompRange])
Your second measure:
Total Product Sales Comparable =
var FilteredTable =
FILTER(
FactSales
,[Sales Amount PY]*[Sales Amount]+0<>0 -- returns false
-- the reason is the same
-- as above
-- and FilteredTable is empty
)
RETURN
CALCULATE(
[Sales Amount]
,ALL(DimProduct)
,FilteredTable
)
You can try smth like this:
Total Product Sales Comparable =
var FilteredTable =
FILTER(
All(DimProduct)
,NOT [Sales Amount PY]*[Sales Amount]=0
)
VAR CurrentCalendarMonth = SELECTEDVALUE(Calendar[CalendarMonth])
RETURN
SUMX(
FilteredTable
,CALCULATE(
[Sales Amount]
,Calendar[CalendarMonth]=CurrentCalendarMonth
)
)
I would like to get the sum product of this table:
example: (0*.0256) + (1*.0468) + (2*.0344) ...
days to departure is a dimension under one table. And Conversions is a measure that I'm showing as % of Grand Total.
Thanks for any advice.
So we have table T with the column [Days To Departure] and the measure [%GT Conversions]
We want a measure to sum all the values of [%GT Conversions] for all the rows of T.
Let's call this measure [Total Formula], since I don't know what it'd be expected to represent
Total Formula =
VAR Total = SUMX( ALL( T ), T[Conversion] )
RETURN
SUMX( ALL( T ), T[Days To Departure] * T[Conversion] / Total )
I have 3 columns in a table: Date, Product, and Volume. Based on this is I want to calculate the cumulative sum (or YTD) column for each of the products.
I know that to calculate cumulative total we use:
YTD_Actual = CALCULATE(Sum(Combined[Actual Volume]),FILTER(Combined,Combined[Date] <= EARLIER(Combined[Date])))
But I want this to additionally filter individual products and do this calculation for that product.
The expected column is shown in the picture below:
As far as you manage to get the Month column in date format, the following works:
YTD =
VAR currProduct = Table1[Product]
VAR currMonth = Table1[Month]
VAR ytdTotal =
CALCULATE(
SUM(Table1[Volume]),
FILTER(
ALL(Table1),
Table1[Month] <= currMonth &&
Table1[Product] = currProduct
)
)
RETURN IF(NOT(ISBLANK(ytdTotal)), ytdTotal,0)
Result: