I have 3 measures:
1) total_trx = SUM(mytable[trx])
2) trx_prev_month = CALCULATE([total_trx], DATEADD(calendar[date], -1,MONTH))
3) monthly_var = DIVIDE([total_trx],[trx_prev_month])-1
If I add a waterfall viz, x-axis with month, it gives me the % of monthly variation and a TOTAL bar at the end that sums all the variations.
I need to reproduce that total number in order to show a KPI as in "so far, we've increased ...%", changing when using a date slicer.
Seems like sum(monthly_var) is not allowed.
Any ideas?
Thank you very much.
Edit1: sample with date filter = Last 4 months
Jul 100 0%
Aug 110 10%
Sep 90 -20%
Oct 80 -10%
Total: -20% <- need a dax to calculate this number and show just -20%
Then if I change the filter to, for example LAST 6 MONTHS, I need to calculate it up to May
In order to get the desired result we will use an intermediate table in our query that will summarize the results by months:
use this code and replace calendar[Year Month] with your Year month column :
SUMX(
SUMMARIZECOLUMNS(calendar[Year Month],"Monthly_int_var",[monthly_var]),
[Monthly_int_var]
)
Related
I have a list of product with revenues across 3 years. However I would like to split the revenue by 60 % and 40% for each year.
For instance:
Book -> 2020 -> 15mil
Book -> 2021 -> 18mil
Book -> 2022 -> 12mil
Therefore in Power BI the revenue should appear as:
2020 -> 60% x 15
2021 -> 40% x 15 + 60%*18
2022 -> 40% x 18 + 60% x 12
2023 -> 40% x 12
How can I code this in Power BI to ensure that the revenue are split accordingly?
Update:
I have tried to do a 60% and 40% split column and additional column of Year +1. How do I add them up on Power BI based on year?
I assumed some data model like the following:
[SalesAmt] = SUM(paid_price)
If we now create a table out of the year and [SalesAmt] we get the following. (My sales values were created for testing purposes)
Now for my understanding: You want to display the SalesAmt (which exact Measure doesn't matter) multiplied by 60% and add the SalesAmt from the previous year multiplied by 40%.
For this we can use the DAX formula SAMEPERIODLASTYEAR(), it takes one argument, the date-field for which you want to retrieve the last year's pendant.
[SalesAmt Buckets v1] =
SALES[SalesAmt] * 0.6
+ CALCULATE(SALES[SalesAmt], SAMEPERIODLASTYEAR(DATES[fq_date])) * 0.4
Explanation to this formula:
We calculate the current year's [SalesAmt] and multiply it by 60%, then we calculate [SalesAmt] and changing the filter context for this calculation by CALCULATE(). At the end we multiply by your 40% and return the result.
Notice how it is less for the firs year (2019), that's because we don't have a previous year for the row context year 2019, so we just retrieve the current year's value times 40%.
For the next years it's correct being 2020 = 40% * 79 + 60% * 95 = 85.
I run monthly reports to show month over month impact on our transportation costs. I need to have a formula that will remove blank rows when there is not a record in the current period or previous period.
Routing Current Month Previous Month
aaaa 100 150
bbbb 125
cccc 200 210
dddd 180
My formula for trying to deal with this is:
MoM PPV =
IF(OR(ISBLANK([$/Container]), ISBLANK([PREVIOUS MONTH $CONTAINER])),
BLANK(),
DIVIDE([OCEAN CONTAINER DIFFERENCE], 'GCF Ocean'[$/Container])
)
EDITED
If your measure returns BLANK(), then power bi desktop automatically remove rows.
Measure = CALCULATE( DIVIDE(sum('Table'[Current]), sum('Table'[Previous])) )
example:
EDITED:
SumOfPrev = CALCULATE(SUM('Table'[Previous]))
SumOfCurrent = CALCULATE(SUM('Table'[Current]))
Measure = CALCULATE( DIVIDE([SumOfCurrent], [SumOfPrev]) )
You can try with visual level filter as shown in attached image. It will remove all the blank record which your measure "MoM PPV" code return.
The questions relates to DAX/PowerBI.
I've been trying to calculate a total for previous month for columns that contain only specific criteria (project name). My table looks more or less like this and is named Project Costs:
Project Name
Date
Cost in Month
Month
Year
X
01/01/2021
2.000,00
1
2021
Y
01/01/2021
1.500,00
1
2021
Z
01/01/2021
4.800,00
1
2021
X
01/02/2021
3.000,00
2
2021
Y
01/02/2021
3.500,00
2
2021
Z
01/02/2021
2.200,00
2
2021
X
01/03/2021
1.000,00
3
2021
Y
01/03/2021
6.000,00
3
2021
Z
01/03/2021
2.000,00
3
2021
I have a slicer in my report that allows me to select from all my projects.
I want to be able to visualize different financial data relating only to the project currently selected with the slicer. I managed set up calculations for cost to date, labour to date etc., however, I am struggling to find a way to calculate a rolling previous month cost relating only to the selected project, that would be susceptible to the slicer in the visuals.
I've tried the following:
Prev Month Cost Rolling =
SUMX(RELATEDTABLE('Project Costs'), 'Project Costs'[Cost in Month],
DATEADD('Project Costs'[Date], -1, MONTH))
And it does not work as it says the max. argument count for SUMX is 2.
I have tried solutions suggested here too, but they don't work either (I might be doing th wrong): Power BI Rolling Total Previous Month DAX
Expected result:
Once the report is filtered to a project Z, in March I would expect to see in card visuals:
Cost to date: 9.000,00
Cost in previous month: 2,200.
When filtered for X in March it would want it to be as follows:
Cost to date: 6.000,00
Cost in previous month: 3.000,00
I want to calculate the entire previous month, not month to date.
I would appreciate any advise on how to tackle it!
Thanks,
J
Have a look at these measures:
Total Project Cost = CALCULATE([Cost], FILTER(ALL(Projects[Date]), Projects[Date] <= MAX(Projects[Date]))) - this shows all historical costs up to the selected date.
Cost = SUM(Projects[Cost in Month]) - can be used for costs in current month, for instance
Cost previous month = CALCULATE([Cost], PREVIOUSMONTH('Projects'[Date]))
Am new to Power BI and appreciate help on DAX for this requirement:
I have a FY slicer (July-June) in my Power BI reports and wants to show monthly trending across different FY years. Target data is structured like this in a table:
Dates | Target
30-06-2018 | 34000
30-07-2018 | 34000
30-08-2018 | 34000
********** | *****
30-06-2019 | 30000
30-07-2019 | 30000
********** | ******
I need to calculate annual variance with below formula to get monthly baseline for next year(2019), then calculate cumulative reduction variance across July-June:
('Target of 30-06-2018') - ('Target of 30-06-2019')/ 12
Dates are linked to another DATE table, which has Financial year and Financial month columns.
Thanks so much in advance for the help!!
Anita
You need to use the DAX PARALLELPERIOD
PARALLELPERIOD(<dates>,<number_of_intervals>,<interval>)
The documentation gives a perfect example:
= CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PARALLELPERIOD(DateTime[DateKey],-1,year))
So your calculation will something like:
= (
CALCULATE(SUM(TargetTable[Target])) -
CALCULATE(SUM(TargetTable[Target]), PARALLELPERIOD(Dates[Date],-1,year))
) / 12
If you want monthly variance, then you need to ensure that Dates[Date] is filtered at a grain to return a table of dates for the entire target month.
You can find a great blog on it here
For next year, I got June Baseline value with SAMPLEPERIODLASTYEAR.
1: Last year value = CALCULATE(SELECTEDVALUE (TargetTable[Target]),
SAMPLEPERIODLASTYEAR (Dates[Date]))
2: Base Target = IF (MONTH(SELECTEDVALUE(TargetTable[Dates])=6, DIVIDE ([Last year value]-SELECTEDVALUE (TargetTable[Target]), 12))
Still need to figure out Cumulative monthly variance across next financial year?
I want to create a visualisation from a dataset which shows percentages that change accordingly when filters are used.
I have a dataset like the below but with over 1 million rows of data covering 18 months. All the fields are text except Month which is a date and SUMofAPPTS which is numerical.
SUPP GEOG1 MODE STATUS TYPE TIME Month Day SUMofAPPTS
AA 00D Face Att 1 1 Day 2018-06 Sun 12
AA 00D Face Att 1 1 Day 2018-06 Mon 119
AA 00D Face Att 1 4 Unk 2018-06 Tues 98
BB 00D Tel DNA 2 1 Day 2018-06 Weds 98
BB 00D Online DNA 3 1 Day 2018-06 Thurs 126
CC 00D Face DNA 1 2 Day 2018-07 Sun 8
I would like a measure which calculates the percentage of SUMofAPPTS by Day and MODE (and the same but for STATUS, TYPE and TIME) which changes when filters are placed on the other fields.
So I think I need to make this simple calculation (which would work in a column if I just wanted to know the percentage per row of the whole dataset) more dynamic so that it works when I filter the data:
PERCENT = 'dataset'[SUMofAPPTS]/SUM('dataset'[SUMofAPPTS])
The end result will be a stacked bar chart with the following attributes:
Day as the Axis
PERCENT as the Value
MODE, STATUS, TYPE or TIME as the Legend
Ability to filter by one, many or all of the fields except Day and SUMofAPPTS
First, create a measure for aggregating SUMofAPPTS:
Total APPTS = SUM(Data[SUMofAPPTS])
Second, create a measure for the percentage:
APPTS % of Selected
= DIVIDE(
[Total APPTS],
CALCULATE([Total APPTS], ALLSELECTED()))
This measure recalculates [Total APPTS] ignoring all filters except those selected by a user (on slicers etc).
Result:
after selections:
Edit
If you need to breakdown by Day (or any other field), you can re-introduce filters like this:
APPTS % of Selected
= DIVIDE(
[Total APPTS],
CALCULATE([Total APPTS], ALLSELECTED(), VALUES(Data[Day])))