sum two values of dimension but show the result only in one of them in PowerPivot / DAX - excel

It might be a easy one but I cannot solve it so please advice.
I would like to add up two months in a measure (like the current and the previous one) but when I represent the figure in a pivot table I want to show the result only in a current month.
Here is the formula I tried:
CALCULATE([Revenue],FILTER(Tbl_Period,Tbl_Period[Month_nr] = 3)) +CALCULATE([Revenue],FILTER(Tbl_Period,Tbl_Period[Month_nr] = 4))
But logically when I represent it in pivot table the revenue is appear under the two months:
See the picture of the result of the below formula:
What I want to achieve instead is the following:
See the picture of the aimed situation:
I already managed to solve with the ALL function to show the value in all the months but not only for July as I wanted. Here is the formula for that one:
Revenue:
=CALCULATE([Revenue],FILTER(ALL(Tbl_Period[Month_nr],Tbl_Period[Period_id]),Tbl_Period[Month_nr] = 3)) +CALCULATE([Revenue],FILTER(ALL(Tbl_Period[Month_nr],Tbl_Period[Period_id]),Tbl_Period[Month_nr] = 4))
Thanks in advance for the help!

I'm a little bit blind, since you haven't mentioned the structure of your Tbl_Period table.
There are many helpful functions built into dax that can save you a lot of work if you have a date table. One that would be relevant here is PREVIOUSMONTH().
Working with just the information you have provided, you can get a measure to show the previous month's revenue like this:
LastMonthRevenue: = CALCULATE([Revenue], FILTER(ALL(Tbl_Period), Tbl_Period[Month_Nr] = MAX(Tbl_Period[Month_Nr]) - 1))
and then
TwoMonthsRevenue: = [Revenue] + [LastMonthRevenue]

Related

Power BI: Compare two columns in a table visual

I am trying to compare two columns in Power BI and only color when there is a difference from one column to another.
Like this:
The pictures are from:
https://community.powerbi.com/t5/Desktop/Compare-two-columns-in-a-table-visual/m-p/272761#M122058
I saw the solution there (the link above), but since it was asked two years ago, I wanted to check if there is a better solution or color formatting I am not aware of.
I have to compare over 70 pairs of columns. That is why I was checking if there is an alternative that does not require to create a column per pair
Or how would you approach it?
I really appreciate any help you can provide.
Conditional formatting has improved. You can now conditionally format a column by other fields. So you can define a difference measure and use that:
Diff = IF ( SUM ( Sales[Sales - DB] ) = SUM ( Sales[Sales - File] ), 1, 0 )
To add to this.
Is there a way to compare two string columns in the matrix table using "new measure"
= if(Column A = Column B, True, False)

How to define an array of numbers with a formula

I have a project where I need to break people into 3 buckets with task lists that rotate quarterly (Phase A = task list 1, B = task list 2, C = task list 3). The goal here is to sort people into the buckets based on a departure date, with the ideal being that they would depart when they're in the C phase. I have a formula already set up that will tell me the number of quarters between the project start date and the person's departure date, so now I'm trying to figure out how to get Excel to tell me if a person's departure date falls within their bucket's C Phase.
I have this formula in a column called DEROSQtr:=ROUNDDOWN(DAYS360("1-Oct-2020",[#DEROS],FALSE)/90,0)
Now the easy way to approach this would be to build a static array and just see if that formula results in a value in the right array, where the numbers in the array define which quarter from Oct 2020 that the bucket's C Phase is going to be in:
ArrayA = {1;4;7;10;13;16} ArrayB = {2;5;8;11;14;17} ArrayC = {0;3;6;9;12;15}
The formula that pulls this all together is then:
=IF([#EFP]="A",IF(IFNA(MATCH([#DEROSQtr],ArrayA,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="B",IF(IFNA(MATCH([#DEROSQtr],ArrayB,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="C",IF(IFNA(MATCH([#DEROSQtr],ArrayC,0),-1)<>-1,TRUE,FALSE),"-")))
Now while this will work for as long as I build out the static array, I'm trying to figure out how to define each of these buckets with a formula that Excel can work with, i.e. bucket A hits phase C in 3n + 1 quarters where n is the number of cycles through all 3 phases, so ArrayA = 3n+1, ArrayB = 3n+2 and ArrayC = 3n. What I'm hunting for here is the best way to define each of the arrays as a formula.
After some additional digging and looking back at how to define each array, I came across the MOD() function in Excel. I was then able to rewrite the formula that does the checking as =IF([#EFP]="A",IF(MOD([#DEROSQtr]-1,3)=0,TRUE,FALSE),IF([#EFP]="B",IF(MOD([#DEROSQtr]-2,3)=0,TRUE,FALSE),IF([#EFP]="C",IF(MOD([#DEROSQtr],3)=0,TRUE,FALSE),"-"))), replacing ArrayA(3n+1) with MOD([#DEROSQtr]-1,3), ArrayB(3n+2) with MOD([#DEROSQtr]-2,3), and ArrayC(3n) with MOD([#DEROSQtr],3).
Since I do not have the data you are calculating your quarter, its difficult to give you exact answer. However, as I understand your have a column which has the formula to calculate the quarter say "Formula_Col"
Solution will be to add a new column and flag it based on the values in "Formula_Col".
If you can give some sample data I can provide exact answer.

How do I calculate the number of years to target in Microsoft Excel

If I have an average YOY growth of say 2.5%, current year sales of $500,000, and target sales of $1,000,000. Is there a way to calculate the number of years until I hit my target (assuming a continued YOY growth rate of 2.5%), without calculating each additional years's sales on a different row?
You can use the NPER function for this:
=NPER(Growth,0,currentSales,-targetSales)
Note that this gives the same result as #Dominique, but is using a built-in Excel function.
Also, by virtue of the nature of Excel financial functions, the signs for the current and future Sales need to be different.
There's a simple formula for this:
Money_end = (1+r/100)^Y*Money_begin
Where:
Money_begin = the starting amount of money, in this case 500000.
Money_end = the finishing amount of money, in this case 1000000.
r = the percent ratio, in this case 2.5.
Y = the amount of years, which you are looking for.
So, your question comes down to solving this equation:
1000000 = (1+2.5/100)^Y * 500000
2 = 1.025^Y
Y = log(2)/log(1.025)
If you want this to be solved by Excel, you might use the formula and use the Solver basic Excel feature for coming up with the same (but numerical instead of analytical) result.

How to remove duplicates from individual powerquery columns without removing entire rows

I have a data table that records cost savings data and I have 1 row per project. This has overall project type data such as annual spend, annual savings, etc. but also has the months the savings fall into. To pivot on this data, I converted it to a table with PowerQuery but some columns repeat such as annual spend for each month where there are savings so I might get 10 rows for savings which is correct, but the annual spend is duplicated 10 times. Can I remove duplicates in just those columns retaining the other data.
I have searched and tried various solutions but haven't found one that works. I am not set on data table format, so am open to anything.
Below is a sample of the data
Sample of PowerQuery
As you will see, Baseline Spend, Negotiated Spend, Savings Amount are all shown for each row and I need to use these in a pivot/slicer.
Any help would be appreciated.
Regards,
Keith
I think one solution might be to "only keep the first1 annual spend per project". More abstractly, "only keep the first value in column(s) X per column(s)Y".
Below is some mock/dummy data. I only want to keep the highlighted values in my annual spend column (as the highlighted values are the first "annual spend" figures per "project").
This is the M code I'm using to achieve this. (To try it, open the Query Editor > Advanced Editor (near top right) > copy-paste code below to there > OK).
let
OnlyKeepFirstValueInColumn = (someTable as table, columnsToNullify as list) as table =>
let
firstRow = Table.FirstN(someTable, 1), // This assumes first row contains a non-blank value.
remainingRows = Table.Skip(someTable, 1),
loopAndNullify = List.Accumulate(columnsToNullify, remainingRows, (tableState, currentHeader) => Table.TransformColumns(tableState, {{currentHeader, each null}})),
combined = firstRow & loopAndNullify
in combined,
FirstValueOfColumnsPerGroup = (someTable as table, groupByColumns as list, columnsToNullify as list) =>
let
group = Table.Group(someTable, groupByColumns, {{"toCombine", each OnlyKeepFirstValueInColumn(_, columnsToNullify), type table}}),
combined = Table.Combine(group[toCombine])
in combined,
aggregatedTable = Table.FromColumns({Text.ToList("aaabbbccccdddeeefg"), List.Repeat({1000}, Text.Length("aaabbbccccdddeeefg"))}, type table [project=text, annual spend=number]),
transformed = FirstValueOfColumnsPerGroup(aggregatedTable, {"project"}, {"annual spend"})
in
transformed
The important bit to understand is this line:
transformed = FirstValueOfColumnsPerGroup(aggregatedTable, {"project"}, {"annual spend"})
in which you should replace:
aggregatedTable with whatever variable/expression contains your table
{"project"} with the name of your "project" column (keep the curly braces {} though as they let you pass in several columns if needed)
{"annual spend"} with the names of whichever column(s) you want to keep only the first value in (keep the curly braces {})
This is what I get (which I think is similar to what you want):
1To keep things simple, we'll say "first" here means the value in the first row. It could have meant "first non-null value" or "first value satisfying some particular condition or logic", but your data suggests the simpler definition will work okay.

Moving total which uses two calculated fields and also uses its previous value-Spotfire

Hi folks I am new to Spotfire and having difficulty in replicating one of the formulas from Excel to spotfire.
Sample Data
Sample data here(excel)
https://docs.google.com/spreadsheets/d/1KSdrIYKlRYG9c3wIM3NwQcLP_Ob8Z2UZ5Cjrdjy8UO8/edit?usp=sharing
and I am trying to replicate the column [Steady Repay-Option Scenario]
Formula used in excel
=IF(B6-IF(C3>0,C2,0)>0,B6-IF(C3>0,C2,0),0)
the above is the formula I have in excel where subsequent columns are calculated by using the previous value and the current values from columns [Monthly impact on cash] and [running total]
This is the formula I have created in spotfire:
if((Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(Sum([Rolling_total_cash_calculated]) over (AllPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) over (AllPrevious([Document_Date_Number])),0)))>0,Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(sum([Rolling_total_cash_calculated]) over (allPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) OVER (allPrevious([Document_Date_Number])),0)),0)
Assumptions--
Data has been pivoted into three columns([Document_Date_Number], Monthly_impact_on_cash_calculated] and [Rolling_total_cash_calculated])
where:
[Scenario opening balance] = 150000000(fixed)
[Document_Date_Number] = Jan,Feb,Mar etc
[Rolling_total_cash_calculated] = Rolling total(excel)
[Monthly_impact_on_cash_calculated] = Monthly impact on cash(excel)
But I get incorrect results for some reason
results in spotfire
But the expected result is
Correct result in excel
So although the results match till Oct as shown above they don't seem to match afterwards.
Please let me know what can I do to get the same values. Any help in deeply appreciated.

Resources