I am working in Power BI and I created a DAX measure that adds up two other DAX measures.
For one measure I need it to ignore the month slicer because I need the total for that category. Is it possible to do so?
Also, is it possible for it to ignore the slicer and still give me the total for unfiltered DAX measure + the date filter DAX measure?
DAX code:
Monthly Total Act =
CALCULATE (
SUM ( 'sheet1'[Amount] ),
FILTER ( 'sheet1', 'sheet1'[Type] = "ACT" ),
FILTER ( 'sheet1', 'sheet1'[Bill] = "Y" )`
)
Monthly Total of Acs =
CALCULATE (
SUM ( 'sheet1'[Amount] ),
FILTER ( 'sheet1', 'sheet1'[Type] = "ACR" ),
FILTER ( 'sheet1', 'sheet1'[Bill] = "Y" )`
)
Adding these two formulas together to get the total monthly.
The monthly total of ACS is where I encounter the problem. I need this to be unaffected by the slicer
The end goal is having the month total of ACS unaffected by the data slicer and add to the monthly total of Act that requires filter by the current month.
Yes, you can add this line as a third filter argument in the calculat function you want to ignore the month slicer:
ALL('tableName'[monthColumnUsedAsSlicer])
Then the monthe slicer will not affect calculations.
Related
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 have a dataset and I want to create a column(not measure) to calculate the count of customers in each month. I don't know how I can count each customer once a month in Power BI.
I wrote this code but it counts the number of frequent customers more than once a month.
myCol = CALCULATE( DISTINCTCOUNT('table'[user_id] ) , 'table'[order_date] )
For example, it's my data:
The true result should be:
but my code returns this result:
How should I write the code for this calculating column to get a true result?
Since you are trying to calculate per month, you need a "year_month" column.
Then:
count_of_customer =
CALCULATE(
DISTINCTCOUNT('table'[user_id]),
ALLEXCEPT('table', 'table'[year_month])
)
Result:
Edit:
You don't need a calculated column, you need a measure:
count_of_customer =
COUNTROWS (
SUMMARIZE ( 'table', 'table'[year_month], 'table'[user_id])
)
In my Power BI model I have a fact table (factSales) that links to a date dimension (dimDate) through a surrogate key DateId. Now I want to add a measure to obtain the max invoice date for each client. But it should be the maximum date ignoring the context (for the date filters). (So if I filter all sales in Q1 2020, then I still want the max invoice date in e.g. 2021).
This is how I got it working:
Add new column in factSales:
Invoice Date = RELATED(DimDate[Date])
Add new measure in factSales:
Last Contract =
CALCULATE( MAX(FactSales[Invoice Date]),
ALL( DimDate )
)
This works, but is there a better way to do this ? Without the extra calculated column. (And without using both-directional filtering).
You can use CROSSFILTER inside CALCULATE:
Last Contract =
CALCULATE (
MAX ( Dates[Date] ),
REMOVEFILTERS ( DimDate ),
CROSSFILTER ( Sales[Date], Dates[Date], BOTH )
)
You can create a measure to return max date using the following dax formula:
Measure = MAX(Sheet1[Date])
To always display the latest date without filter by slicer, you need to click on the slicer then goto Format >Edit Interaction >click none on the specific visual. In the following case, the max date is still 8 Nov 21 even though the slicer latest date is Sep 21
Try this:
Last Contract =
CALCULATE ( MAX ( DimDate[Date] ), ALL ( DimDate ), FactSales )
This removes filtering from a slicer on DimDate[Date] by still applies FactSales as a filter table.
I would like to calculate Percentage value of total (same as inbuilt "show as -> percentage of grand total" but using DAX).
I have seen solutions
Percent of Total Windowed in Power BI DAX
and
Power BI DAX - Percent of Total Column with FILTERs
and
How to calculate Percentage out of Total value in DAX (Power BI Desktop)
but unfortunately all of them do not work for me (I get all rows filled with 100% for calculated column)
Idea is to have percetage of total but be able to apply date filter and see percent value of shown data, not entiry query
I tried as in above mentioned solutions:
Percentage =
DIVIDE(
SUM( All_Years[Price:] ),
CALCULATE(
SUM( All_Years[Price:] ),
ALLSELECTED( All_Years )
)
)
First of all I do not understand why do they take SUM in numerator. If I use just
Percentage =
DIVIDE(
All_Years[Price:],
CALCULATE(
SUM( All_Years[Price:] ),
ALLSELECTED( All_Years )
)
)
then situation looks better, I get percent value of total table in each row. But then when I apply date filter in Visual I see total 3.5% (which is correct if we consider full query and not slice that I got after applying filter)
Leaving ALLSELECTED blank also does not resolve the problem.
what am I missing?
I have a table which contains a list of products scores by date:
From this table, I have to make a plot of the cumulative percentage of each quality by date.
At this moment I have the percentage of each class by day:
For that I used this measurement:
Measure =
CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) ),
ALLEXCEPT ( Table1, Table1[Score] )
)
/ CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( ALL ( Table1 ), Table1[Date] = MAX ( Table1[Date] ) )
)
But this only considers the percentage of each day. I need to consider all previous dates. E.G. for day 2 I need to consider days 1 and 2, for day 3 I need to consider days 1,2,3 and so on.
How can I accomplish this?
in my opinion, you need a calendar for the date first, you can create a table easily bay dax function =CALENDARAUTO() And mark it as a calendar table,
After that, you can use a DATEMTD or a DATEYTD function for your coding purpose.
here are the steps:
1 - https://learn.microsoft.com/en-us/dax/calendarauto-function-dax
select left pane --> table --> modelling / create table and add dax formula
2- reference the table as a date table, right click on the table from the right pane
after then you can use data functions like YTD MTD ,
new measure :
1st mesure : AVG1 = AVG(DATA_)
2nd measure : YTD AVG ALL = CALCULATE([AVG1];DATESYTD(CALENDAR[DATE]))
REF: https://learn.microsoft.com/en-us/dax/dateadd-function-dax
then you can use MONTH(CALENDAR(DATE)) on left and YTD AVG as a value at any table...
regards.
SUNAY