DAX TOTALQTD does not show GrandTotal properly - aggregation

Using the DAX function to build out the Quarter to Date calculations:
Measure 1 QTD:=TOTALQTD([Measure 1],DATESYTD(DimDate[Date],"09-31"),ALL(DimDate))
it functions properly aside from the Grand Total:
What I need is for the GrandTotal not to be the last quarter to date sum, but the total year end. In this case it would be ~$915,000.
How can DAX to configured to permit this?

You are asking it to perform a different computation for the Grand Total. To do this you need to have some sort of condition to let it know when you want to compute the Grand Total and when you want to compute everything else.
One possibility is to use the HASONEVALUE function like this:
IF(HASONEVALUE(DimDate[Date],
TOTALQTD([Measure 1], DATESYTD(DimDate[Date], "09-30"), ALL(DimDate)),
TOTALYTD([Measure 1], DimDate[Date], ALL(DimDate), "09-30"))
This should give you QTD when you have a single date filter context and YTD for the Grand Total since it has multiple dates values in the filter context.

Related

What dynamic array formula can I use to calculate runway or burnrate in Excel?

I'm using dynamic array functions in Excel (SCAN, MAP, LET, BYCOL, etc); wihtout VBA or regular SUMIF formulas, to create a runway or burnrate-type table. So, I start with a $10,000 budget, month 1 $2,000 are spent, so $2,000 come out of the budget, month 2 $3,000, and so on until the cash available is 0 for the remaining months of the year. With a table showing how much cash was used from the budget per month, Desired outcome in the case below.
A
B
C
D
E
F
1
Budget
$10,000
2
Month
1
2
3
4
5
3
Expense
-$2,000
-$3,000
-$7,000
-$4,000
-$2,000
4
Desired outcome
-$2,000
-$3,000
-$5,000
$0
$0
Note that the Desired outcome amount is how much of the budget was used to cover the expenses.
Notice that Month 3 I spent $7,000, but from the budget, only $5,000 were left; so that's what I show.
Studied all the dynamic array (SPILL!) functions and lambda functions that I could find on the internet (this video by excelisfun is great) but I couldn't make it work. Some combination between SCAN or MAP would be the go-to solution I would think.
The solution should be one formula that leverage MS365 dynamic array functions.
I used REDUCE to get your result:
=LET(budget, -B1,
expenses, B3:F3,
DROP(REDUCE( 0, expenses,
LAMBDA( x, y,
HSTACK( x,
IF( SUM(x,y)>=budget,
y,
budget-SUM(x))))),
,1))
It creates a cumulative sum of expenses and checks if it's greater than or equal to the budget (since your expenses are negatives I converted budget to a negative).
If it is it, the value of expenses is shown, otherwise the remainder of the budget minus the cumulative sum of the expenses.

Grab minimum time in year

As an athlete I want to keep track of my progression in Excel.
I need a formula that looks for the fastest time ran in a given season. (The lowest value in E for a given year. For 2017, for example, this is 13.32, for 2018 12 and so on.
Can you help me further?
Instead of formula you can use PIVOT
Keep the Year in Report Filter and Time into Value. Then on value field setting select min as summarize value by.
So every you change the year in the Filter the min value will show up.
=AGGREGATE(15,6,E3:E6/(B3:B6=2017),1)
15 tell aggregate to sort the results in ascending order
6 tells aggregate to ignore any errors such as when you divide by 0
E3:E6 is your time range
B3:B6 is you Year as an integer.
B3:B6=2017 when true will be 1 and false will be 0 (provide it goes through a math operation like divide.
1 tells aggregate to return the 1st value in the sorted list of results

DAX measure to iterate each row for correct division (for total as well)

I am not sure if there's a way in DAX to create a measure that would help me with the following:
Calculate the efficiency by day
Display the total efficiency in a pivot table / PowerBI matrix as the overall total and not as sum of the daily efficiency
Here's a simple example:
Where:
Total Categories = Category1 + Category2 + Category3
Efficiency = (Total Categories + Category4*0.33)/Category4
At first I've created measures for each category (e.g. TotalCateg1 = SUM[Category1] etc.) and hopping to get the right result in the end. My problem is I am not able to get both the daily efficiency and the total right. Is there a way around it?
For Total Categories use this formula:
=SUM([Category 1])+SUM([Category 2])+SUM([Category 3]) .
then for the Efficiency use this formula:
=([Total Categories]+SUM([Category 4])*0.33)/SUM([Category 4])

Summing up values with criteria and sumif doesn't work

Accounting Record A Accounting Record B
Date Amount Date Amount
12/17/2016 1,800.00 10/13/2016 -1,800.00
12/21/2016 5,200.00 12/10/2016 -5,200.00
12/25/2016 25,000.00 12/12/2016 -25,000.00
12/30/2016 37,000.00 11/2/2016 -37,000.00
These are two accounting records which I am going to add up. What I want is to have the sum of the amounts for December 2016, so the estimated output is 38800 (1800+37000 since 5200 and 25000 are canceled out). I used this formula =SUMIF(A3:A6,AND(MONTH(A3:A6)=12,YEAR(A3:A6)=2016),B3:B6)+SUMIF(C3:C6,AND(MONTH(C3:C6)=12,YEAR(C3:C6)=2016),D3:D6)
but it returned 0. May I know the correct formula?
Thanks
AND and OR operators are not array friendly. Your best friend here is SUMPRODUCT with aligned arrays, in a way that permits the multiplication of summed values by the appropriate logical conditions:
=SUMPRODUCT(B3:B6*(MONTH(A3:A6)=12)*(YEAR(A3:A6)=2016))
+ SUMPRODUCT(D3:D6*(MONTH(C3:C6)=12)*(YEAR(C3:C6)=2016))

DAX Calculation with Datesbetween Ignores all Datefilters

I am starting with DAX.
I have a standard date table and a table with sales. When I try to show the running total with the below formula the month filter is ignored, as shown:
The formula is:
Prov YTD VJ 2:=CALCULATE(FIRMPROV[SumProv];
All(Kalender[Jahr]);
DATESBETWEEN(Kalender[Datum];
Min(START_YTD[start_ytd]);
MIN(END_YTD[end_ytd])))
A good way to calculate running totals is by using the FILTER and EARLIER functions, but a prerequisite to that is that you need to create a Month Number column (ie. Jan = 1, Feb = 2, Mar = 3, etc.)
Then, you can use the following DAX:
CALCULATE(SUM([SumProv]),ALL(FirmProv),FILTER(FirmProv,[Month Number]<=EARLIER([Month Number])))
EARLIER basically is DAX's way of interpreting the current row. You're telling DAX to sum ALL of the rows in the FirmProv table where the month number is less than or equal to the current row (AKA running total).
Here's the result (note the numbers aren't exactly like yours, I just quickly mocked it up to show the example):

Resources