what kind of measure or column will use here - powerbi

[Please refer to the below image. I want to create a stacked column chart but I don't have a column that includes 0-30, 30-60, 60-90, etc. How did I put this range on X-axis?
And I didn't understand what kind of measure is used for "LAST 3 MONTH average" & "LAST 12 MONTH average ".
Can you please assist me with the same? ]
https://i.stack.imgur.com/AEnoa.png

Here is Microsoft documentation on using grouping and binning features in Power BI: https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-grouping-and-binning
You can create a measure for last 3 month average like this:
3 Month Average = CALCULATE(
AVERAGE(Table[value]),
FILTER(Table,
Table[date] >= DATE(YEAR(TODAY()),MONTH(TODAY()-3),DAY(TODAY()))
)
)

Related

Line chart Power BI - different value for different period of time

I am using power BI and I would like to create a line chart which contains values from two tables (sales history and sales prediction). So for the past 12 months, the line should reprensent the sales history and for the next 6 months, the line reprensents sales prediction. Here is what the data looks like, lets say we are in June 2021:
I know there is a way to do it in DAX but I don't know how to do it by myself. Thanks a lot in advance for your help !
You can achieve this by
Delete any relationship between Calendar and the other two tables if there is any, as we are going to use DATESBETWEEN function to calculate
Create two metric like below, you might need to adjust the column names as per your project
Sales History Amount = IF('CALENDAR'[Date] <= TODAY(), CALCULATE(SUM('Sales History'[Amount]), DATESBETWEEN('Sales History'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Sales Prediction Amount = IF('CALENDAR'[Date] >= TODAY(), CALCULATE(SUM('Sales Prediction'[Amount]), DATESBETWEEN('Sales Prediction'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Add these two metrics in the table and use the Date from the Calendar table as X axis.
Format the first metric to solid line, and dash line for the second
Calendar should be linked to your tables.
Prediction Amount =
VAR lastSalesDate = MAX('Sales History'[Date])
VAR currentPredictionAmnt =
CALCULATE(
SUM('Sales Prediction'[Amount])
,KEEPFILTERS('CALENDAR'[Date]>lastSalesDate)
)
RETURN currentPredictionAmnt + SUM()
Sales Amount =
SUM('Sales History'[Amount])

Can't do a cumulative sum with legends in a stacked chart (Power Bi)

I am new to Power Bi. My manager asked me to illustrate the growth of the company with a stacked chart.
All is fine when i don't add legends to it (the different stores). But when i do this happens :
Broken chart
I want the orange part (Omega company) to also appear in 2022.(even though they made no benefits for that year)
What measure do I need to make this happen ?
Any help would be much appreciated.
Here's a simplified caption of what the excel file for the power bi report looks like.
Thank you !!
Excel sample
You can use the Quick measure "Running Total" to achieve that, but you need a separate "Dates" table that you can build as a calculated table via
Dates = GROUPBY('Table','Table'[Date])
and that you need to relate 1-to-many to your original table.
Now in the Quick measures UI for "Running total" you set the Base value to "Sum of Benefits" and the Field to "Date - Year"
With that measure "Benefits running total in Year" and your Excel sample data from above your Stacked column chart looks like this:
What does your measure look like?
If you have a relationship between your fact table and date dimension table, you can try something like this
Running Total Benefits =
CALCULATE (
SUM ( 'Fact Table'[Benefits] ),
ALL ( 'Date Table' ),
'Date Table'[Date] <= EARLIER ( 'Date Table'[Date] )
)
Or use DATESBETWEEN function if they don't have relationship

Calculate Rolling Day Total in PowerBI/Dax

I have a table in PowerBI that has the column "Date" and "Sales". I want to create a measure and display it in a table that computes a rolling 7 day total of the "Sales" column. To be clear, I want to see this overtime, I do not want it for a single day, I want to create a table exactly like I am showing below, thanks!
Rolling total can be make using the quick measure feature underneath the New Measure & New Column buttons in the Home Tab.
Select Calculation -> Rolling Total in the Totals Section
If not then you can make a formula (Both for Measures):
Rolling Total =
CALCULATE(
SUM('Sheet1'[Sales]),
FILTER(
ALLSELECTED('Sheet1'[Date]),
ISONORAFTER('Sheet1'[Date], MAX('Sheet1'[Date]), DESC)
)
)
Rolling Total 2 =
CALCULATE(
SUM(Sheet1[Sales]),
DATESMTD(
Sheet1[Date])
)

Power BI dynamic ranking with some blank values and using slicers

I have a table with 15 people that each month get 7-day scores. I want to use the RANKX formula in Power BI to rank the lowest (1) to the highest average score.
This works fine if I look at all, but start to act weirdly when I use a slicer and only look at one or two months for example. The ranking doesn't start with 1 anymore?
I use this formula:
Rank = RANKX(
ALLSELECTED('Score Table'[Person]);CALCULATE(AVERAGE('Score Table'[Score]));;ASC;Dense)
Look at the image attached, please.
Help much appreciated image showing the issue
Can you try this and see if it works?
Rank =
RANKX(
CALCULATETABLE(
VALUES( 'Score Table'[Person] ),
ALLSELECTED( 'Score Table'[Person] )
),
CALCULATE( AVERAGE( 'Score Table'[Score] ) ),
,
ASC,
Dense
)
Let's think about the original code step by step.
It iterates over "Person 1" to "Person 20" and calculates the average score of that person.
Evaluate the average score of the person of current filter context (say "Person 1").
Find the ranking position of "Person 1" in 20 persons.
In the step (1), it includes all Persons from 1 to 20 because there is no Person filter in the visual. Here, it looks there is no scores of Person 15 and 18 in the selected period, so it evaluates to BLANK.
Now, the document of RANKX says,
If expression or value evaluates to BLANK it is treated as a 0 (zero) for all expressions that result in a number, or as an empty text for all text expressions.
The average scores of Person 8 and 15 are BLANK, so RANKX treats it as 0. Now going back to Person 1, her average score was 62.43, and there were two people with average score of 0. Therefore, the rank of Person 1 will be 2.
By wrapping 'Score Table'[Person] with VALUES inside CALCULATETABLE, you can omit persons who has no scores in the selected period.

DAX Dynamic Date Averages

I am trying to create a single measure that will calculate a date average, depending on the drill down on a time barchart.
The bar chart has 5 time pieces in the hierarchy. Year - Quarter - Month - Week -Day
As I drill through the bar chart, I want a measure that will dynamically calculate the Yearly Avg - Quarterly Avg - Monthly Avg, Weekly Avg, Daily Avg.
For example, lets say the barchart is on the Year Level and displaying 4 bars representing 2016-2019. The vale of the measure would be COUNT(UnitID) / 4 because there are 4 bars currently displayed on the X axis.
Lets drill into 2018 to the month level. There are 12 bars representing Jan-Dec. The value of the measure would be COUNT(2018 UnitIDs) / 12 because there are 12 bars currently displayed on the X axis.
Lets drill into 2019 to the month level. There are only 10 bars representing Jan-Oct. The value of the measure would be COUNT(2019 UnitIDs) / 10 because there are only 10 bars currently displayed on the X axis.
Finally, lets not drill down, but just expand the hierarchy from year to month. We go from the yearly view showing 4 bars to the monthly view showing 12. But the Jan total is the sum of 2016Jan + 2017Jan + 2018Jan + 2019Jan. The measure needs to interpret this as COUNT(All UnitIDs) / 12 because there are 12 months currently displayed on the X Axis.
I'm basically trying to figure out how to create a measure that counts whatever number of values are on the X axis at any given time.
Thank you all for your advice and feedback. I'm really looking forward to testing your responses and seeing if they work!
It sounds like you are looking for a way to show the same value for each year, quarter, month, etc.
I wonder how this would make sense as a visual, but if that is the case, your measure would be something like this.
Average Count UnitIDs in Drilldown Periods =
-- At which level the report is drilled down?
VAR CalendarDrilldownLevel =
IF(ISFILTERED('Calendar'[Day]), "Day",
IF(ISFILTERED('Calendar'[Week]), "Week",
IF(ISFILTERED('Calendar'[Month]), "Month",
IF(ISFILTERED('Calendar'[Quarter]), "Quarter",
IF(ISFILTERED('Calendar'[Year]), "Year", "None")))))
-- Total count of UnitIDs in the entire period
VAR TotalCount = CALCULATE([Count of Unit IDs], ALLSELECTED('Calendar'))
-- Number of years, quarters, months, etc. based on the drilldown level
VAR CountOfPeriods = CALCULATE(
SWITCH(
CalendarDrilldownLevel,
"Year", DISTINCTCOUNT('Calendar'[Year]),
"Quarter", COUNTROWS(
DISTINCT(
SELECTCOLUMNS(
'Calendar',
"Year", 'Calendar'[Year],
"Quarter", 'Calendar'[Quarter]
)
)
),
"Month", COUNTROWS(
DISTINCT(
SELECTCOLUMNS(
'Calendar',
"Year", 'Calendar'[Year],
"Quarter", 'Calendar'[Quarter],
"Month", 'Calendar'[Month]
)
)
),
-- Similar lines follow for weeks, days, and in case of no drill down.
),
ALLSELECTED('Calendar')
)
RETURN DIVIDE(TotalCount, CountOfPeriods)
Maybe you are trying this to show average line in the visual? In that case, you can just define a simple measure like COUNT('Your Table'[UnitID]) and add an average line in column chart visual setting. (You can find that in Analytics section)