Error in dax formula - excel

i'm new to dax. im trying to sum the amount of fatalities per year.
My formula:
= SUMMARIZE (
'TableCrash',
'TableCrash'[Year],
"Fatal", SUM ( 'TableCrash'[Fatalities] )
)
-
example:
SUMMARIZE(<table>, <groupBy_columnName>[, <groupBy_columnName>]…[, <name>, <expression>]…)
Source

There isn't anything wrong with your formula. The problem is how you are using it. Because it returns a table you would usually incorporate this snippet into a larger formula. You can install DAX Studio into Excel to test these snippets. In this case you would execute:
EVALUATE
(
SUMMARIZE (
'TableCrash',
'TableCrash'[Year],
"Fatal", SUM ( 'TableCrash'[Fatalities] )
)
)
But if you have a table that contains Year and Fatalities you don't need any formula to calculate sum of Fatalities. Try to drop both fields into a Power View or pivot table and Fatalities will sum automagically.

Related

Calculate monthly efficiency in power pivot

I am very new to this power pivot and dax Commands ,kindly help me out here
my sample table looks like this :
Now to calculate monthly efficiency i need to make a measure which satisfies below criteria:
Sum the efficiency for each distinct date & divide by the count of distinct dates for the month
so far for days my below formula is working , but when i group the date into month it is only showing the sum, so kindly help me how to achieve this ;
Actual Efficiency CL2:=CALCULATE(SUM(CL1[Day Wise Efficiency]),DISTINCT(CL1[Date (dd/mm/yy)]))
Divide part is not in your formula, below DAX might help:
Actual Efficiency CL2 :=
DIVIDE (
CALCULATE ( SUM ( CL1[Day Wise Efficiency] ) ),
CALCULATE ( DISTINCT ( CL1[Date (dd/mm/yy)] ) )
)
Note that DISTINCT ( CL1[Date (dd/mm/yy)] ) is not required in the sum as dates in rows will be unique.
To Divide the sum at month level DISTINCT ( CL1[Date (dd/mm/yy)] ) is required as we need how many days a month has.
At day level there will always be 1 to divide by.
Thanks

DAX Power Pivot Building a Cash Flow Statement (indirect method)

Here is the current file for this question (download from OneDrive)
I have the following data model:
This is the sample data in each table:
I have this DAX measure to calculate the running sum and get the subtotals for the income statement:
IF (
HASONEVALUE ( DIM_IncStatement[Label] );
CALCULATE (
[Total Value];
ALL ( DIM_IncStatement );
DIM_IncStatement[Code] < VALUES ( DIM_IncStatement[Code] )
)
)
And this one for the operational profit:
=
CALCULATE (
[Subtotal Income Statement];
ALL ( DIM_IncStatement[Level1] );
FILTER ( DIM_IncStatement; DIM_IncStatement[Code] = 9 )
)
Currently the pivot table for the income statement looks like this:
As the cash flow statement if built upon some information from the income statement, I need to get the information and put it in the corresponding rows.
This is the basic structure of the cash flow statement:
QUESTION:
What's the DAX measure to get the "Operational profit", "Cost depreciation", "Expense depreciation", and finally the EBITDA (which is the sum of the previous) in place in the cash flow report?
I'have tried this for the operational profit, but after adding the measure, then pivot table gets empty:
=
CALCULATE (
[Operational profit];
ALL ( DIM_Cash_Flow );
FILTER ( DIM_Cash_Flow; DIM_Cash_Flow[Report code] = "OP" )
)
If anybody can give a hint, I'd really appreciate it...being trying for hours!

Sum columns in Power BI matrix

I am working on a matrix in Power BI and I am not figuring out how to sum each column recursively until the total:
And this should be the resulting matrix (as an example, rows):
Some clarifications:
The months (columns) are dynamically generated based on the transaction month. I could filter the data to get the same data for only three months.
"Nombre proveedor" stands for "Vendor name".
I don't care about "Total" row.
These are my values:
So, I think I should create a measure with DAX to replace "Accounting Balance" to sum the previous column (month) or show nothing (to avoid zeroes).
Searching on internet I found several sites to get the running totals by rows, but not by columns.
Any suggestions?
Try Something like this:
Maesure =
CALCULATE (
[Accounting Balance],
FILTER (
ALL ( 'table' ),
'table'[Transaction month] <= MAX ( 'table'[Transaction month] )
)
)

I need a pivot table of the pivot table I've created

I have a fact table that covers several weeks of tasks in MS Project, and each week is timestamped with that week's week-ending date. I am trying to get the previous week's remaining work for certain tasks (they have a flag called Should Finish This Week set to TRUE).
I have a formula that enables me to create a pivot table that, when I manually sum the values column (it's basically a MIN of the previous week's remaining hours by assignment id), it gives me the result I want.
However, I cannot figure out how to "build this pivot table in DAX" so that I can summarize the resulting sum of hours by department. Right now, I just have the number of hours by task (assignment id) for last week.
Here's the formula:
Simple Min :=
CALCULATE (
MIN ( DataMerge[PreviousWeekRemainingWork] ),
AssignmentHistory[ShouldFinishThisWeek] = TRUE (),
DataMerge[BestPercentComplete2] < 1,
DataMerge[CompletedFLAG] = FALSE (),
USERELATIONSHIP ( 'Calendar'[Date], DataMerge[End of Week] )
)
And with that formula, I can output the following pivot table (this is just a small sample):
The desire is to get a SUM of the Simple Min value by Department. I've tried all the tricks of PowerPivot that I know. Here' the latest iteration of a formula I tried, but the amounts by department are all incorrect, and the grand total is off by about 1200 to the high side.
HRS Remaining More Simple :=
SUMX (
SUMMARIZE (
DataMerge,
DataMerge[ResourceDepartments_R],
DataMerge[AssignmentId]
),
[Simple Min]
)
Any help on this last formula would be greatly appreciated. When I manually sum the pivot table, I come up with ~4300 hours, which is the correct number, so I can verify the formula once given.
Thanks!

How to refer to a single value in a Calculated Column in a measure (DAX)

I have a table(Data_all) that calculates daycount_ytd in one table.
[Date] is in Date Format.
[Fiscal Year] is just year. eg: 2016
Calculated Column
daycount_ytd=DATEDIFF("01/01/"&[Fiscal Year],Data_all[Date],day)+1
Im trying to create a measure that refers to this Calculated Column
Measure:
Amt_X Yield %:=[Amt X]/([Amt Y]/365* (Data_all[DayCount_YTD]))
I get the error that Data_all[DayCount_YTD] refers to a list of values.
How do i filter the expression to get a single value without using a aggregation function eg:(sum, median)?
Or perhaps, is there another way to achieve the same calculation?
You've arrived an a fundamental concept in DAX and once you've worked out how to deal with it then the solution generalises to loads of scenarios.
Basically you can't just pass columns into a DAX measure without wrapping them in something else - generally some kind of mathematical operation or you can use VALUES() depending on exactly what you are trying to do.
This measure will work OK if you use it in a PIVOT with the date as a row label:
=
SUM ( data_all[Amt X] )
/ (
SUM ( data_all[Amt Y] ) / 365
* MAX ( data_all[daycount_ytd] )
)
However you will see it gives you an incorrect total as it is in the latest for the entire thing. What you need is a version that iterates over the rows and then performs a calculation to SUM or AVERAGE each item. There is a whole class of DAX functions dedicated to this such as SUMX, AVERAGEX etc. You can read more about them here
It's not totally clear to me what the maths behind your 'total' should be but the following measure calculates the value for each day and sums them together:
=
SUMX(
VALUES(data_all[date]),
SUM(data_all[Amt X]) /
(SUM(data_all[Amt Y]) / 365 * MAX(data_all[daycount_ytd]))
)

Resources