Power BI : Monthly averages - powerbi
I know similar questions have been asked and answered previous to this, but for the life of me, cannot get any of those working with my limited knowledge on Power BI.
I have a table which contains 8 weeks worth of data which for most parts, spans 3 months. I currently calculate the daily average which is the "total" divided by the "total in". However what I need to do, is to display the average based upon the calendar month. Therefore, September will have a difference average to that of October and that of November.
Here's a sample of the data:
Date,Total In,Total Out,Daily Average,Total,Month
27 September 2017,10773,264,97.61,11037,September
28 September 2017,11198,382,96.70,11580,September
29 September 2017,17753,1122,94.06,18875,September
30 September 2017,9568,649,93.65,10217,September
28 October 2017,11434,938,92.42,12372,October
29 October 2017,1541,60,96.25,1601,October
30 October 2017,918,4,99.57,922,October
31 October 2017,8565,24,99.72,8589,October
01 November 2017,11452,635,94.75,12087,November
02 November 2017,7785,531,93.61,8316,November
So for November I would like to have the figure as (11452 + 7785) / (12087 + 8316) * 100 = 94.29%. Obviously, that figure would be present for all dates in November as an extra column. For October it would be (11434 + 1541 + 918 + 8565) / (12372 + 1601 + 922 + 8589) * 100 = 95.63%. I would then use the extra column and plot it on a line/bar chart.
So the above data would become:
Date,Total In,Total Out,Daily Average,Total,Month,Monthly Average
27 September 2017,10773,264,97.61,11037,September,96.00
28 September 2017,11198,382,96.70,11580,September,96.00
29 September 2017,17753,1122,94.06,18875,September,96.00
30 September 2017,9568,649,93.65,10217,September,96.00
28 October 2017,11434,938,92.42,12372,October,95.63
29 October 2017,1541,60,96.25,1601,October,95.63
30 October 2017,918,4,99.57,922,October,95.63
31 October 2017,8565,24,99.72,8589,October,95.63
01 November 2017,11452,635,94.75,12087,November,94.29
02 November 2017,7785,531,93.61,8316,November,94.29
I am having trouble getting my head around the SUMMARIZE functions etc in order to get this working without any help. So any help and explanation would be greatly appreciated.
Thanks.
Create a DAX using the EARLIER function should do the trick:
Month Average =
VAR sum_total_in =
CALCULATE(
SUM('table'[Total In]),
FILTER(
'table',
'table'[Month] = EARLIER('table'[Month])
)
)
VAR sum_total =
CALCULATE(
SUM('table'[Total]),
FILTER(
'table',
'table'[Month] = EARLIER('table'[Month])
)
)
RETURN sum_total_in / sum_total
So basically it sums the Total In and Total within the same month and returns the division.
Results:
P.S. You'll need to add the year to the filter as well if you have data across years with the same month.
I see you're asking your question from a DAX perspective, but here's a Power Query based answer that's quite easy. Starting with your table in Power Query (Power BI's Query Editor):
Select the Month column, then Transform -> Group By, and set up the dialog box like this...
and click OK.
You'll see this:
Then click the button at the top of the
AllData column to expand the nested tables, and set up the dialog box like this...
and click OK.
You'll see this:
Now click Add Column -> Custom Column, and set up the dialog box like this...
and click OK.
You'll see this:
Now select the first three columns (Month, Sum Total In, Sum Total) and click Home -> Remove Columns.
You'll see this:
You can double-click the Month.1 column title and rename it if you like.
Related
Sorting with Power BI Using Direct Query
I have a table visual. I am using Direct Query, NOT import mode. Originally, I had my months sorting alphabetically (April, August, December, etc, like this), but I wanted them to sort by Month Number, AFTER sorting by year in the visual. I tried to be clever by concatenating the month number to the month name, so that the values look like this: 01 - January 02 - February ... 09 - September 10 - October 11 - November 12 - December To the left of this month_name column, I have a year column. I want the data to be sorted, ascending, by year, and then by the month column I created. How can I do this in my table?
How to get percentage of total yearly sales for several years in Power BI?
Probably my question is not self-explanatory, and for that reason I'm using a dummy table to explain what my problem is and what I would like to get. I have a table like following |channel|year|revenue| online 2011 10 reseller 2011 40 online 2012 15 reseller 2012 45 online 2013 28 reseller 2013 28 I visualized this data in a clustered bar chart (axis= year, legend=channel, and value= revenue) and it shows me numbers of yearly revenue contributed by different channel, for example in 2011, online 10 and reseller 40. But I would like to show it as percentages of total sales for 2011 (for example, 2011 online 20% & reseller 80%, for 2012 online 25% & reseller 75%, for 2012 online 50% & reseller 50%. How it can be achieved? probably I need to get a new measure but don't know the DAX. Any suggestion is appreciated.
You can use simply calculation: YourRevenueMeasure = SUM('YourTable'[Revenue]) PercentageOfSales = DIVIDE( [YourRevenueMeasure], calculate( [YourRevenueMeasure], FILTER(ALL('YourTable'), 'YourTable'[Year] = SELECTEDVALUE('YourTable'[Year]))) )
First create this below Measure- revenue_ = var total_ = CALCULATE( SUM(your_table_name[revenue]), ALLEXCEPT( your_table_name, your_table_name[year] ) ) RETURN MIN(your_table_name[revenue])/total_ Now change the measure type as % and use it in the Values field in Clustered Bar Chart.
Filter table based on a specific date plus 7 days
I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March. I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date. Any pointers much appreciated. Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below- Considering your date table name is- Dates selected_date = SELECTEDVALUE(Dates[Date]) seven_day_starts_from = DATEADD(Dates[Date],-7,DAY) Now create your calculated measure first like- total_sales = SUM(Sales[sale]) Here comes how you will always calculate last 7 days sales considering the selected date in the slicer- 7_day_sales = ( CALCULATE( [total_sales], DATESBETWEEN( 'Dates'[Date], [seven_day_starts_from], [selected_date] ) ) + 0 ) Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.
Use DAX to calculate sales for last full month in period
My filter context contains all dates in a financial year (eg. 1-Jul-2017 - 30-Jun-2018). I would like to calculate sales for the most recent full month in the selected financial year. Eg. For the current financial year 1-Jul-2017 - 30-Jun-2018, I would like to calculate total sales for August, since it is the most recent full month in the period as of today (15-Sep-2016). I have tried the following: Prem $ Last Closed Month = CALCULATE(SUMX(SalesFlat, [gross_amt_plus_lhc_annual]), DIM_DATE[MONTH_END_DATE] < NOW()) - CALCULATE(SUMX(SalesFlat, [gross_amt_plus_lhc_annual]), DATEADD(DIM_DATE[MONTH_END_DATE], 1, MONTH) < NOW()) But am getting the error "A function 'DATEADD' has been used in a True/False expression that is used as a table filter expression. This is not allowed." Any ideas? Thanks.
Try using PREVIOUSMONTH(<dates>) function Prem $ Last Closed Month = SUMX(PREVIOUSMONTH(<dates>),calculate(sum(TotalSales)) Replace TotalSales with your measure for sales.
Maybe this will help. If I start with this table, named "SalesFlat"... ...and I add a column using this code... MostRecentFullMonth = SUMX(FILTER(SalesFlat,EOMONTH(SalesFlat[MONTH_END_DATE],0)=EOMONTH(NOW(),-1)),SalesFlat[gross_amt_plus_lhc_annual]) ...I get this result: Since today is 16 September 2017, the most recent full month was August 2017. The total gross_amt_plus_lhc_annual for August 2017 was 43 + 66 + 98 + 58 + 9 = 274. You could also use this to set up a measure, instead of a column, and you can use it in your PowerBI dashboard like with this card:
Drilling down periodical time data (subscriptions with start & end date) per month?
I'm currently struggling with following request in PowerBI: I have two CSV files as PowerBI queries, one which defines fiscal months, and another one which lists all subscriptions including start and end date: Fiscal month CSV: Month Fiscal Start Fiscal End January 03.01.2016 04.02.2016 February 05.02.2016 03.03.2016 March 04.03.2016 06.04.2016 April 07.04.2016 02.05.2016 May 03.05.2016 06.06.2016 June 07.06.2016 03.07.2016 July 04.07.2016 05.08.2016 August 06.08.2016 02.09.2016 Subscription CSV: Account-ID Subscription-Start Subscription-End Item Count 101 08.01.2016 07.02.2016 5 102 15.01.2016 14.03.2016 3 103 05.01.2016 04.06.2016 10 101 08.02.2016 07.03.2016 3 104 10.04.2016 09.05.2016 5 105 16.04.2016 15.07.2016 2 My challenge now is to drill down all subscription item counts per fiscal month as a powerBI table. Note: an Item Count is valid for a fiscal month if its Subscription-Start < Fiscal End and its Subscription-End > Fiscal End. (Example: A subscription from 15.01.2016 - 14.02.2016 should be counted in january, but not in february) PowerBI table (schematical example): Month Item Count January 18 February 16 March 10 April 17 May 12 June 2 July 0 August 0 How can I implement this report in PowerBI? THX in advance for your help and BR bdriven
I've found following solution for my problem: First I've created a new Table and made a crossjoin of the two queries. Then I've filtered for the lines, where my Subscription Start was before the Fiscal Month End and Subscription End was after the Fiscal Month End. Based on this new table I can create all respective reports. Example Code see below: Fiscal Month Report = FILTER( CROSSJOIN( ALL('Fiscal_month'); ALL('Subscription') ); ('Subscription'[Subscription-Start] < 'Fiscal_month'[Fiscal End] && 'Subscription'[Subscription-End] > 'Fiscal_month'[Fiscal End]) )