Calculate Average year to date in Power BI - powerbi

I have a challenge in power BI to calculate average YTD.
enter image description here
I am looking for make the average for month two take in consideration data from month one and so on.
Any idea how to do that in Power BI?
Thank you in advance,
Mahmoud

Not knowing why the solution by Alexis didn't work for you, I've made the assumption that you only have one table (called 'Data'), with two columns as your image showed.
Step one:
Add two new columns (if you do this in Power query or power bi doesn't matter): [Month_name] and [Month_number].
[Month_Name] = FORMAT([Date]; "MMM")
[Month_number] = MONTH([Date])
Step two:
Add a measure
YTD Avg =
var currentMonth = MAX([Month_number])
RETURN
DIVIDE(
CALCULATE
SUM(Data[Amount]);
ALL(Data[Month_Name]);
Data[Month_number] <= currentMonth
);
CALCULATE(
COUNTROWS(DATA);
ALL([Month_Name]);
Data[Month_number] <= currentMonth
);
0
)
This should generate the following table:
Hope this helps. Please don't hesitate to ask if you have further questions.

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])

How to calculate percentage of each category and only selected items in Power BI using DAX

I am working on some education data. There are 4 categories and each of them have got a list of items. I have got the numbers. I have made a Matrix table with the Categories and Items in the Rows and the Numbers as Values. What I want to achieve 2 things
Show percentages for each of the items based on the category subtotal
"Not stated" and "Not applicable" in each category should not be included to calculate the percentages.
Can someone please show me how to create a new measure using DAX in Power BI to achieve this.
Please see the below example screenshot in Excel for detail. Table example
Here is a Power BI file with the example data - https://1drv.ms/u/s!AubIV2PXG9p4gql0qImMTHvl4ZDAWg?e=2flwnP
I am new to Power BI and DAX. Any help will be greatly appreciated. Thank you
Follow these below steps-
Create this Measure first-
category_total =
VAR current_row_category = MIN(Education[Category])
RETURN
CALCULATE(
SUM(Education[Number]),
FILTER(
ALLSELECTED(Education),
Education[Category] = current_row_category
&& Education[Item] <> "Not stated"
&& Education[Item] <> "Not applicable"
)
)
Now create the % calculation measure as below-
percentage =
IF (
MIN(Education[Item]) = "Not stated" || MIN(Education[Item]) = "Not applicable",
BLANK(),
(MIN(Education[Number])/[category_total])
)
Now add the above Percentage measure to Metrics value and the output will be as below-

Power BI - Daily difference as a value and percentage

I have a power BI report that has the following
Date, City, Town, Order number,
What i would like to do is create a report that shows the total orders (volume) for every day (which i can do as that is nice and easy) but I also wanted to show the difference from the previous reported day (some days we dont have data, eg bank holidays etc)
I am new to power bi and my technical skills are not brilliant.
Thank you in advance to anyone who is able to provide a solution.
Welcome to SO. There are a few ways of achieving it - you can even calculate these values directly in Power Query - it all depends on your data model and how the report itself is constructed.
Below are two solutions that you might want to consider:
Solution 1 - calculated column
This adds a new column to your table. The overall concept is to find the maximum date that is less than the current row's date and retrieve the respective value.
Volume t-1 =
var ThisDate = Table1[Date]
var PrevDate =
MAXX(FILTER(ALL(Table1[Date]), Table1[Date] < ThisDate), Table1[Date])
var PrevValue =
MAXX(FILTER(Table1, Table1[Date] = PrevDate), Table1[Current Volume])
return
PrevValue
You can now use this new column to calculate the difference between the current value and the previous value, e.g.:
Difference = [Current Volume] - [Volume t-1]
Solution 2 - measure
mVolume t-1 =
var ThisDate = MAX(Table1[Date])
var PrevDate =
MAXX(FILTER(ALL(Table1[Date]), Table1[Date] < ThisDate), Table1[Date])
var PrevValue =
MAXX(FILTER(ALL(Table1), Table1[Date] = PrevDate), Table1[Current Volume])
return
PrevValue
Similar to the first solution, you can now calculate the difference between this measure and the [Current Volume] field. However, the final formula will depend on your report and visualization filters. For example, if you add a table with Dates column (daily frequency), you can add the following measure to your table visualization:
[mDifference] = MAX(Table1[Current Volume]) - MAX(Table1[Volume t-1])
I hope this is a good starting point - good luck!

How to Rank a Measure which is Average Field, Power BI

I am new in Power bi. I have a table where I have agents details. I have their scores as well. I have date wise data into table where the following columns are available -
I have created created measure for Average of Score where Metric is UES AGGREGATE -
I have to get the ranking of the advocate(s) for the Average Score (UES AGG). I have tried this measure for Ranking calculation -
Rank_UES = RANKX('RankSummary',[RKS_UESAGG])
I am getting wrong ranking. Please help me , how to solve the issue.
Thanking You.
Use ALL function with RANKX.
Rank_UES =
RANKX (
ALL ( 'RankSummary'[AgentfullName] ),
[RKS_UESAGG]
)
I do not know if your [RKS_UESAGG] get you what you want. Suppose you want average sales you make something like this:
Rank_UES =
RANKX (
ALL ( 'RankSummary'[AgentfullName] ),
AVERAGE ( 'RankSummary'[Amount] )
)
https://learn.microsoft.com/en-us/dax/rankx-function-dax

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])
)