I have a powerbi report which is running a dax formula to calculate a custom measure. In the picture below, the total at the bottom doesn't seem to add up to the individual rows. I've been trying my luck for some time and can't seem to figure out why this is.
The DAX formula used is as follows
SumRest<24hrs7Day = CALCULATE(
DISTINCTCOUNT(WorkTimeDirective[EmployeeKey]),
FILTER(
ADDCOLUMNS(
SUMMARIZE(WorkTimeDirective,Employee[EmployeeKey],'Date'[DateKey]),
"totRestHrs", CALCULATE(MAX(WorkTimeDirective[RestHours])
,DATESINPERIOD('Date'[DateKey], LASTDATE('Date'[DateKey]), -7, DAY))
),
[totRestHrs]<24
),
WorkTimeDirective[IsEmployeeAbove18]=1
)
Any idea why this is and what I am doing wrong.
For using SUMX the main step is listing the values which you are iterating over, which it typically a table or column. In this case it sounds like you would do a column.
For the example I just had it call the measure you already defined, since breaking DAX calculations into smaller pieces makes writing/testing complex formulas easier.
The idea being that it would iterate over the unique values which are in your TableName[Site Name], then run the [SumRest<24hrs7Day] under that context. I used TableName for the table due to not knowing the name for the table.
SUMX_Example = SUMX( VALUES( TableName[Site Name], [SumRest<24hrs7Day])
Related
im struggling with the following problem. I have categorical variables and and Amount column. What I want to do is, to write a dax measure which calculates the moving/rolling Sum, like you see in the third column "Dax Measure". Did not find any inhouse Dax function for that.
moving sum
EDIT:
Result Table with Dax Measure
Source Table
This will work if the category is always sorted ASC.
Dax measure =
VAR _currentRank = RANKX(ALL('Table'[Category]),CALCULATE(MIN('Table'[Category])),,ASC)
RETURN
CALCULATE(
CALCULATE(SUM('Table'[Amount]),TOPN(_currentRank,VALUES('Table'[Category]),MIN([Category]))),
ALL('Table'[Category])
)
Using RANKX to define the other and aggregating for all the item before it.
I am trying to calculate the TotalFTE, but I can't figure it out. I am fairly new to DAX and trying to make the best of it with some studycases.
The table contains a lot of columns, but these are the columns that are needed for the measure.
The measure should sum the highest FTE in a year per ID and ignore the blanks in ID.
I've build a measure that gives an error when I try to visulise the result in a card. My measure: TotalFTE = CALCULATE(MAX(Table[FTE]), FILTER(Table, DISTINCT(Table[ID])))
Any feedback?
Moving forward, please post data as tables in stack and refrain from provide the data as image.
Measure =
SUMX (
GROUPBY (
'Fact',
'Fact'[year],
'Fact'[ID],
"#Max", MAXX ( CURRENTGROUP (), 'Fact'[FTE] )
),
[#Max]
)
I need to perform a simple calculation in DAX that consists of 2 steps.
Step 1: Calculate the median price change (%) per product.
Step 2: Calculate the average of all the medians calculated in Step 1 while counting each product (calculated median) only once.
Using a calculated column for Step 1 doesnt seem to work out for me because the medians from Step 1 are subject to change as soon as the user filters the table (i.e. using a date slicer) in the report.
Therefore, I will need to get both Steps performed dynamically in a measure.
I'm pretty sure the answer to: "Is there any way to achieve this?" will be "Yes". I just lack the know-how at this point and can't seem to find the answer.
I would recommend to create 2 differents measures to solve this problem.
But since you need to create only 1 measure you can use the following DAX function:
Median_per_product =
VAR __step1 = CALCULATE( MEDIAN('Table'[Price_Change] ), ALLEXCEPT('Table', 'Table'[Product] ))
VAR __step2 = AVERAGEX( VALUES( 'Table'[Product] ), CALCULATE( MEDIAN( 'Table'[Price_Change] ) ) )
RETURN
IF(
HASONEVALUE('Table'[Product]) &&
NOT(ISBLANK( __step1 )),
__step1,
__step2
)
This is the expected result:
I've been struggling to find a way to achieve the result of a matrix visualization in Power BI, in a line and clustered column chart.
I have tried using ALLSELECTED, ALL, ALLEXCEPT in order to ignore one filter but no matter how I try it, I'm not reaching my end goal.
CarCountPerCategory =
CALCULATE(
DISTINCTCOUNT(Table[CarID]),
ALLSELECTED(Table[Filter])
)
This still breaks down the measure to the Filter level instead of ignoring it. I am looking for something that will give me the total distinct count regardless of the Filter column. E.g. TimesReshopped 1 - 190 on all 3 columns, TimesReshopped 2 - 182 on all 3 columns of the Filter Column series. I need this as a sidestep in order to divide the distinct car count to the total distinct car count per times reshopped in order to reach the percentage that I am looking for. (the one in the matrix)
Can someone help me with some advice? Thank you.
Try this:
[Total Category Count]:=
SUMX ( SUMMARIZE ( Table, Table[TimesReshopped] ), [Count of CarID] )
I got to the bottom of this by using ALLEXCEPT and providing all the filter that I was using:
CarCountPerCategory =
CALCULATE(
DISTINCTCOUNT(Table[CarID]),
ALLEXCEPT(Table,Table[Year],Table[Month],Table[LocationName],Table[CustCode],Table[TimeReshoped])
)
Within Power BI Desktop (Version: 2.39.4526.362 64-bit (September 2016), I have written a DAX Statement that behaves differently when the column is sorted by another vs when it is not sorted by another.
Measure:
Sum of Sales Across All Months =
CALCULATE ( SUM ( SalesAmount ), ALL ( 'Date'[MonthName] ) )
When the MonthName column is unsorted by another column, the measure behaves as I expect. Eliminating the filter context of the MonthName column. However, as soon as I set the MonthName column to be sorted by another column (e.g., MonthNumber) the "ALL" context reset is lost and it reverts back to the MonthName context.
Does anyone know if this is a bug or if I am misunderstanding something?
Thanks!
When one column sorts by another column, the DAX that Power BI generates includes the sort-by column, even though it's not visible in your visual. Therefore, for the measure to behave as you'd expect, you need to remove the filter context from both columns, even though only one is visible:
Sum of Sales Across All Months =
CALCULATE (
SUM ( SalesAmount ),
ALL ( 'Date'[MonthName] ),
ALL ( 'Date'[MonthNumber] )
)
It's unintuitive, but I don't know that it's a bug. There's a blog post that describes the behaviour you're seeing here: https://blog.crossjoin.co.uk/2015/12/15/power-bi-desktop-sort-by-column-and-dax-calculations-that-use-the-all-function/