I'm having problems with implementing TOP N slicer into my dashboard. I would like to have a single select TOP 5, TOP 10, TOP 20 and TOP 30 slicer which will show items with the biggest count.
I partially managed to achieve this and it works while I have only one column added to the y-axis (I use horizontal bar chart) and my measure to the x-axis but when I add another column to legend field everything falls apart.
These are my measures:
TopN_test =
VAR Selected_Top = SELECTEDVALUE('Top N'[Select Top N])
RETURN
SWITCH(TRUE(),
Selected_Top = 0,[count_all_current],
RANKX(
ALLSELECTED(Skills[Skill correct]),
[count_all_current]
)
<= Selected_Top,
[count_all_current]
)
count_all_current =
CALCULATE(
COUNT('Skills'[Skill correct]),
FILTER('Skills', 'Skills'[DateIndex] = 6),
FILTER('Skills', 'Skills'[Proficiency]<>"-")
)
I will be grateful for any advice how to adjust it.
I added a calculate and Selected_Top Variable as a filter. Can you please check if this code works for you.
TopN_test =
SWITCH (
TRUE (),
Selected_Top = 0, [count_all_current],
RANKX ( ALLSELECTED ( Skills[Skill correct] ), [count_all_current] ) <= Selected_Top, CALCULATE ( [count_all_current], Selected_Top )
)
Related
I need to calculate the difference between each year and plot that change in a line graph
In Power BI your pivoted (Excel) table will get you nowhere. Be sure to unpivot all your "YYYY Score" columns in PowerQuery first. This should give you something like:
Next create an explicit measure for your score:
Max Score = MAX('Table'[Score])
With this you can now create your desired "Score Change":
Score Change =
VAR cursor =
MAX ( 'Table'[Year] )
VAR prevYear =
CALCULATE (
MAX ( 'Table'[Year] ),
'Table'[Year] < cursor
)
VAR prevScore =
CALCULATE (
[Max Score],
'Table'[Year] = prevYear
)
RETURN
IF ( NOT ( ISBLANK ( prevScore ) ),
[Max Score] - prevScore
)
Finally put the results in a matrix visual or a line chart:
Hello Lovely People of SO,
I hope you guys are having a great day!
I have the following dataset
REGION
ID
STATUS
DC
1
NEW
ED
2
NEW
FR
3
OLD
FR
4
NEW
GI
5
OLD
GI
6
OLD
GY
7
NEW
GY
8
OLD
GY
9
OLD
GY
10
OLD
GY
11
OLD
GY
12
NEW
RT
13
NEW
TX
14
NEW
TX
15
NEW
I will first want to know how to use DAX to calculate the percentage of ID with STATUS ="OLD" by REGION
Intuitivatly in Python I can group by REGION and then summarize the number of OLD and NEW STATUS but here in PBI DAX things are not somewhat stright forward yet for me since I am learning so thanks you for helping my out with that, my main goal is to create a bar chart that will show the percentage of OLD STATUS by REGION and add a horizontal line that will display the global average of percentages, this is my own data summary
and my desired viz would look like this:
but I have no clue was to how to do that in dax in power bi thank you so much if you guys can help me out If you can reference some code online to do this or if there is a special bulti-in function to calculate this horizontal line thanks a million I will be super attentive to all of your comments
and let me know if It works for you:
OldPercent_Measure =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( YourTable, YourTable[REGION] ),
"STATUS OLD",
CALCULATE ( COUNTROWS ( YourTable ) + 0, YourTable[STATUS] = "OLD" ),
"TOTAL", CALCULATE ( COUNTROWS ( YourTable ) ),
"% OLD",
ROUND (
DIVIDE (
CALCULATE ( COUNTROWS ( YourTable ) + 0, YourTable[STATUS] = "OLD" ),
CALCULATE ( COUNTROWS ( YourTable ) )
),
2
)
)
VAR PercentOld =
SUMX ( TblSummary, [% OLD] )
VAR GlobalAverage =
AVERAGEX ( TblSummary, [% OLD] )
RETURN
PercentOld
Then create a column chart, put [REGION] column in X_axis, and put OldPercent_Measure in the Y_axis[Values field]. I hope It solves your problem.
To calculate Global Average, the same code above. The only difference is to replace PercentOld with GlobalAverage after "RETURN" statement. Like This:
......
......
RETURN
GlobalAverage
Extra Info:
You want to see the result of your summary table:
EVALUATE
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( YourTable, YourTable[REGION] ),
"STATUS OLD",
CALCULATE ( COUNTROWS ( YourTable ) + 0, YourTable[STATUS] = "OLD" ),
"TOTAL", CALCULATE ( COUNTROWS ( YourTable ) ),
"% OLD",
ROUND (
DIVIDE (
CALCULATE ( COUNTROWS ( YourTable ) + 0, YourTable[STATUS] = "OLD" ),
CALCULATE ( COUNTROWS ( YourTable ) )
),
2
)
)
VAR PercentOld =
SUMX ( TblSummary, [% OLD] )
RETURN
TblSummary
Resulting Screen:
To find out how to put average line:
You need to go analytics pane.
Here is a good link to do that:
https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-analytics-pane
One way to get the average for OLD is to create a calculated column for %. Then use DAX to find the average of just the ones with OLD status, using:
CALCULATE(AVERAGE([% column]), FILTER(table name, STATUS = “OLD”))
The graph is a cummulative histogramm (the second left to right, top line). The line is a constant line at analytics. I used the same measure for value there. Have a nice day.
Rate =
VAR Regions = VALUES(tbl[REGION])
VAR sumOfRates=
SUMX(
Regions
,DIVIDE(
CALCULATE(COUNTROWS('tbl'),tbl[STATUS]="OLD")
,CALCULATE(COUNTROWS('tbl'))
)
)
RETURN
DIVIDE(sumOfRates,COUNTROWS(Regions))+0
The average price is 28.87 and I want to calculate and visualize the number of products with a price higher than 28.87 on a row by row basis. The total number is 25.
In the table visual below, I only see the values above average when using the hardcoded value (_avg2), and not when using the formula (_avg). Please refer to the measure below. I only switch around _avg and _avg2 in line 9 in the two columns.
countAvg =
VAR _avg = AVERAGE( ( Products[UnitPrice] ) )
VAR _avg2 = 28.87
VAR _aboveAvg =
CALCULATE(
COUNT( Products[ProductName] ) ,
FILTER( Products , [Unit Price] > ( _avg ) ) )
RETURN _aboveAvg
Below you can see the difference in a snapshot of the visual.
Question: Is my defined variable _avg incorrect in terms of making it visible on a row level (evaluation context)? Anyhow, what should it be to make it work? Having it as a hardcoded value (_avg2) is not useful.
Thanks in advance!
Try changing the filter context of the _avg formula:
VAR _avg = CALCULATE(AVERAGE( Products[UnitPrice] ), ALLSELECTED(PRODUCTS) )
I need to calculate pareto but in graph we can only see top 10 items but pareto should be calculated from all items in the selected date period. So e.g. if I have date 1.10.2021 and I have 20 values for that date. I can display only 10 in powerbi, how can I ignore filter for TOPN10 in dax and calculate pareto from 20 values (in graph it wont show 100 percent for pareto calculation)
I am posting filters from PowerBI
DEFINE
VAR __DS0FilterTable =
TREATAS({FALSE,
BLANK()}, 'Breakdown'[Less then 30 sec])
VAR __DS0FilterTable2 =
TREATAS({TRUE}, 'Breakdown'[IsReportedInterval])
VAR __DS0FilterTable3 =
TREATAS({"Reported"}, 'Reported Filter'[Reported])
VAR __DS0FilterTable4 =
TREATAS({DATE(2021, 10, 1)}, 'Date'[Date])
VAR __DS0FilterTable5 =
TREATAS({"Morning"}, 'Shift'[Shift Name])
VAR __SQDS0BodyLimited =
TOPN(10, __SQDS0Core, [Breakdown__min_], 0)
Here is Pareto calculation - If I use ALLSELECTED pareto is calculated from rows filtered by powerbi filters, when I use ALL it will remove all filters which is not correct because I would get sum of all rows excluding date filter. Any ideas ?
Pareto Breakdown Description:=
VAR TotalQuantity =
CALCULATE ( SUM ( Breakdown[DurationSeconds] ), ALLSELECTED( Breakdown ) )
VAR AllBreakdowns =
SUM ( Breakdown[DurationSeconds] )
VAR SummarizedTable =
SUMMARIZE (
ALLSELECTED ( Breakdown ),
'Breakdown'[Description SK],
"Amount", SUM ( Breakdown[DurationSeconds] )
)
VAR CumulativeSum =
SUMX ( FILTER ( SummarizedTable, [Amount] >= AllBreakdowns ), [Amount] )
RETURN
DIVIDE( CumulativeSum, TotalQuantity )
It will sound maybe little bit silly but I found a workaround - so I removed the filter to show only top 10 rows and within the graph I changed minimum category width which at the end shows only 10 bars (10 are hidden)
Can anybody please help me in getting Total Sale in one bar in Bar Chart visual as show below in picture.
I have calculated total in dataset only just to show the example.
Unlike with a table or matrix visual, to get a total on a bar chart you have to do it manually by creating a new table to use as your axis and a new measure to switch between the total and the parts.
See this community post for example.
Here's how you can create a new table to use as your axis:
ChartAxis = UNION ( VALUES ( Sales[City] ), ROW ( "City", "All" ) )
You'll also need a new measure to put on the chart:
SalesByCity =
VAR AxisCity = SELECTEDVALUE ( ChartAxis[City] )
RETURN
IF (
AxisCity = "All",
SUM ( Sales[Sales] ),
CALCULATE ( SUM ( Sales[Sales] ), Sales[City] = AxisCity )
)