Power BI Measure Calculate % - powerbi

I please need assistance to calculate % based on the below table.
Table 1 (Fixed Table - Total vehicles per branch)
Table 2 (Distinct Count - Total vehicles based on vehicle regsitation) Current Measure Calculation shown below.
Table 3 (Percentage of Table 2 / Table 1, using Branch Table as Unique Identifier)
Branch 1 = 5
Branch 2 = 5
Branch 3 = 10
Branch 4 = 7
Count Loads = DISTINCTCOUNT('DEL-MAN-REP'[Registration Number])
Vehicles 1 = 5
Vehicles 2 = 3
Vehicles 3 = 1
Vehicles 4 = 4
Branch 1 % = 100%
Branch 2 % = 60%
Branch 3 % = 10%
Branch 4 % = 57%
Any assistance will be appreciated.

If you are in the Data section of Power BI(matrix looking icon on the right task bar), there is a button in the 'Modeling' menu called 'New Column'. Click that and it will create a column named "Column" with the formula set to "Column = ". If you change the "column" in the formula it will change the column name.
Now, start typing the column name you want to use that has the 'Vehicles' data and divide that with the 'Branch' data. finally, press the '%' button under Formatting in the Modeling tab.
If for whatever reason any Branch does not have any vehicles(0), you will need an error handler. so it would look like IFERROR(Vehicles/Branch,0)

Related

Sum of rows that satisfy a calculated measure in Power BI

All.
I have a set of data that includes the following:
Store Name
Survey ID
Number of surveys per store
Score
Each survey has a score, and then the overall score for that store is calculate as an average.
The score is a calculated measure based off 3 other calculated measures. These are created as below:
Overall Score 1 = CALCULATE(CALCULATE(COUNT('Table'[Score 1]), 'All Detail'[Score 1] = 5) / (COUNT('Table'[Score 1]))) * 100
Overall Score 2 = CALCULATE(CALCULATE(COUNT('Table'[Score 2]), 'All Detail'[Score 2] = 5) / (COUNT('Table'[Score 2]))) * 100
Overall Score 3 = CALCULATE(CALCULATE(COUNT('Table'[Score 3]), 'All Detail'[Score 3] = 5) / (COUNT('Table'[Score 3]))) * 100
Score = ([Overall Score 1] + [Overall Score 2] + [Overall Score 3])/3
I am wanting to count how many stores have beat a target score.
Currently I have a calculated measure which indicates that the store has beat the target:
Achieved = IF([Score] >= 60, 1, 0)
This works well on a cube at Store level, telling me that the average score for the store is over 60 or not, as below:
However, I am struggling to get the total of stores that have achieved target. In the example above the total would be 3 stores.
I have tried to create a filter measure as below:
Total Achieved = COUNTROWS(FILTER('Table', [Achieved] = 1))
However, this brings back the number of surveys per store that have beat the target. Examples below:
As you can see the Total Achieved calculated measure works well at a survey level but this is not the desired output.
Example of what I am looking for as the output below:
Any advice would be appreciated. I have tried to use calculated columns but with no luck.
Hi this is the expected behavior of table visual first step is to create a summarize table as below. Here I have only group by from ‘Table'[Store] use your own grouping conditions.
s
sumtable =
ADDCOLUMNS(
SUMMARIZE(
‘Table’,
‘Table'[Store],
),
”Surveys”,SUM(Table[Surveys]),
"Score" ,[Score]
)
After that for the above summarize table create the measure as below
Achieved = IF(sumtable[Score] >= 60, 1, 0)
This will ensure your results.

DAX Power BI Conditional filtering

Sample file
The column c of a table T can have the values 1, 2 or 3. I want to filter the table such as when the user selects value 1 nothing is filtered. When the selected value is 2 then show only the rows with the c column containing the value 2 or the value 3 not the value 1 and finally if the selected value is 3 then show only those rows containing 3 in the c column. The slider or a plain filter must be single selection not multi because otherwise it would violate one of the user's business rule.
Selected Show
1 all rows
2 rows with 2 or 3
3 only rows with 3
I tried to create columns and to create measures but I can't get anywhere. Any directions?
I agree that the disconnected table might be the best workaround here. I hope this solution will work with your actual file.
Step 1 - create a new disconnected table
FilterC = DISTINCT(T[c])
Step 2 - make sure that your slicer is sourced from the new table (FilterC)
Step 3 - create a measure that will return 1 for rows that we want to see, and 0 for rows that we want to hide:
mFilter =
var Filter_C = SELECTEDVALUE(FilterC[c])
var Row_C = SELECTEDVALUE(T[c])
return
SWITCH(
Filter_C,
"1", 1,
"2", IF(OR(Row_C = "2", Row_C = "3"), 1, 0),
"3", IF(Row_C = "3", 1, 0)
)
Step 4 - add this measure to the table, or even table filters will suffice.
Step 5 - start switching the values!
First you need to set it to a number column.
Second, you could write complex measures and use a disconnected table, but the best option is to use the correct slicer. There is a Greater than or Equal To option.

How to incorporate thresholds for limit check with a provided static value to compare against?

here is the instance:
Column 1 Column 2 Column 3
2.99 4 Price OK
1.99 4 Price below limit
12.99
5.99 6 Price OK
1.99 6 Price below limit
8.99 6 Price OK
So for Power BI context Column 2 is a custom column from power query, the goal is to set a threshold value for column 2 pack size, in this instance pack size of 4 needs to check for minimum price of $2.99 (higher is ok), below the price should be below limit, in instance of column 2 blanks (result should also be blank). In the instance of size 6 the minimum price to check for is 5.99.
Is there a decent way to go about this?
Let's do this in two steps. First, create a column MinPrice that defines your minimum prices.
if [Column 2] = 4 then 2.99
else if [Column 2] = 6 then 5.99
else null
Then create a column that compares the actual and the minimal
if [Column 1] = null or [Column 2] = null then null
else if [Column 1] < [MinPrice] then "Price below limit"
else "Price OK"
If you have a bunch of unique values in Column 2 that you need to create rules for, then create a reference table that you can merge onto your original table and expand the MinPrice column instead of the first step stated above.
Column2 MinPrice
-----------------
4 2.99
6 5.99
8 7.99
...

How to Calculate 3 Month Rolling Average with my current dataset in Power BI?

I'm new to power BI and i require your assistance. I want to create a visualisation showing the average number of tickets from the previous 3 months and compare it with the current month. Is there any easy way to do this?
I have tried many solutions online but it dosen't work. I think it is because my dataset may not suit the solution.
My data:
Tickets | Date
1 | 6/30/2019
1 | 6/10/2019
1 | 7/1/2019
0 | 7/2/2019
1 | 6/30/2019
There are many more columns and rows. The value of ticket is either 1 or 0 and the date can be repeated. This is the data i received from an API.
This is what i currently have
The data would get bigger and bigger as time goes by.
I would want to add a 3month rolling average line in this current visualization that i have.
Thank you!
Here we go:
First I created a column FirstDayMonth,this I use to group all data of the same month
FirstDayMonth = EOMONTH(Tickets[Date];-1)+1
My table looks like:
Next I create a summarized table grouped by the FirstDayMonth
TicketsMonth = SUMMARIZE(Tickets;Tickets[FirstDayMonth];"Amount"; SUM(Tickets[Tickets]))
I add a column Ave3PrevMonth
Ave3PrevMonth =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
var periodStart = DATE(totalMonths/12;MOD(totalMonths;12);1)
var periodEnd = TicketsMonth[FirstDayMonth]
return
CALCULATE(SUM(TicketsMonth[Amount]);
FILTER(TicketsMonth; TicketsMonth[FirstDayMonth] >= periodStart && TicketsMonth[FirstDayMonth] < periodEnd))/3
This is the tricky bit as Power bi is not strong with dates..
I added an extra column PeriodStart to show the date from where average is taken:
PeriodStart =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
return DATE(totalMonths/12;MOD(totalMonths;12);1)
End result:

PowerBi Change Card values to previous month Value if Current month value is not available

I am working on powerbi, using data over 2 months period, writing dax queries and trying to build reports.
I am trying to show the monthly values in cards visuals.
And i am able to do it using the measure below.
Sample Data:-
PlanPrevMon = CALCULATE([PlanSum],PREVIOUSMONTH('Month Year'[Date]))
CustomKPI = IF(ISBLANK([PlanSum]),"No Data Available ",[PlanSum])&" "&IF([PlanSum]=[PlanPrevMon],"",IF([PlanSum] > [PlanPrevMon],UNICHAR(8679),UNICHAR(8681))&IF([PlanSum]<=0,"",""))
But here i don't want user to choose the month values from slicer.
I would like to show the card values as
if current month value is not available then it should compare with the previous month value automatically as shown in an image below
For example, Apr-2017 value is not available; in this scenario I would like it to compare with the Mar-2017 value.
If Mar-2017 value also not available, then the previous month value and so on
Edit
I tried what #user5226582 suggested but still getting wrong values as below image.
As you can see i restricted to crosscheck whether the value is getting in a right way of not.
But not.
This is the measure i have used as #user5226582 suggested.
c =
var temp = 'Revenue Report'[Date]
return CALCULATE(LASTNONBLANK('Revenue Report'[Planned Rev],
'Revenue Report'[Planned Rev]),
ALL('Revenue Report'),
'Revenue Report'[Date]<=temp)`
Can you please correct me if i am doing anything wrong
Does this help...?
To get the PlanPrevMon column to show like this, I first created a new index column:
id = COUNTROWS(FILTER(Sheet1, EARLIER(Sheet1[Date],1)>Sheet1[Date]))
Then I used the index to help create the PlanPrevMon column in two steps:
Step 1: I made one column named PlanPrevMon1.
PlanPrevMon1 = SUMX(FILTER(Sheet1,Sheet1[id]=EARLIER(Sheet1[id])-1),Sheet1[PlanSum])
Step 2: I made another column named PlanPrevMon.
PlanPrevMon = if(ISBLANK(Sheet1[PlanPrevMon1]),
if(Sheet1[id]=1,0,CALCULATE(LASTNONBLANK(Sheet1[PlanPrevMon1],Sheet1[PlanPrevMon1]),ALL(Sheet1),ISBLANK(Sheet1[PlanSum]))),
Sheet1[PlanPrevMon1])
For the card, I used this measure:
Card = CALCULATE(LASTNONBLANK(Sheet1[PlanPrevMon],1),FILTER(Sheet1,Sheet1[id]=max(Sheet1[id])))
I hope this helps.
You can use LASTNONBLANK DAX function.
Example data:
a b
1 1
2
3 2
4
5 3
Calculated column:
c =
var temp = Table1[a]
return CALCULATE(LASTNONBLANK(Table1[b],Table1[b]),ALL(Table1),Table1[a]<=temp)
Results in:
a b c
1 1 1
2 1
3 2 2
4 2
5 3 3