dax row context
4 Topicscreate dax measure to remove context filter
hi everyone im trying to create a measure that remove the conext filter in a table visual with if statement condition i was trying to use 'all' function to remove the filter from the column but still not working. current measure : calculate(sum('categories trans'[achievement]), all('categories trans'[Base_type]) in the above example , i want to ignore the filter by (base_type) column in one category (zeed) and keep it for the other categories. for example: if category= 'zeed' i want the achievement measure to return 441 and for other categories i want the achievment measure to return same values above.1.1KViews0likes2CommentsMultiple row Context within Iterators
Hello Community, I am trying to compute a table using DAX with date wise sales and its running average of last 5 days. I have this following code which works fine. However i reached here after some trial and error and i am unsure why the other DAX which i tried didn't work when i thought they should work (based on my limited knowledge and experience) DAX - Version 1 - Works Fine running_avg_table = VAR date_sale_table = SELECTCOLUMNS ( SUMMARIZE ( Sales, Sales[OrderDateKey], 'Date'[Date] ), "Date", 'Date'[Date], "sales", [Sales Amount] ) VAR final_table = ADDCOLUMNS ( date_sale_table, "running_avg", AVERAGEX ( FILTER ( date_sale_table, [Date] >= ( EARLIER ( [Date] ) - 4 ) && [Date] <= EARLIER ( [Date] ) ), [sales] ) ) RETURN final_table Desirable output - DAX Version 2 - Unable to understand why this version do not work. In this version, I have brought AverageX function in a seperate variable and used Sumx as an outer function just to have multiple iteration of date_sale_table. running_avg_table_1 = VAR date_sale_table = SELECTCOLUMNS ( SUMMARIZE ( Sales, Sales[OrderDateKey], 'Date'[Date] ), "Date", 'Date'[Date], "sales", [Sales Amount] ) VAR avg_last_5_days_sales = SUMX ( date_sale_table, AVERAGEX ( FILTER ( date_sale_table, [Date] >= ( EARLIER ( [Date], 1 ) - 4 ) && [Date] <= EARLIER ( [Date], 1 ) ), [sales] ) ) VAR final_table = ADDCOLUMNS ( date_sale_table, "running_avg", avg_last_5_days_sales ) -- invokes context transition RETURN final_table Output from DAX 2 I have two queries with respect to this piece of code. 1. I think there are 3 row context being created when defining "avg_last_5_days_sales" measure. First by the outer function Sumx, then by Averagex and lastly by Filter function. However, i think the DAX recognises this to have 2 row context only. This is evident from the fact that i cannot set "2" as an integer value for the 2nd parameter of Earlier function. I am not sure where i am going wrong with this? 2. Why variable "avg_last_5_days_sales" when used as a measure call in "final_table" variable do not yield the average of sales for the preceding 5 days period? My argument here is that as this is a measure call, it should have "calculate" as the implicit outer function. Addcolumn being an iterator should result into context transition in that case and should provide the average of the last 5 days sum. When i use Averagex function directly in the final_Table (as in case of correct DAX version), i am getting the correct answer. Supporting Material / Info - One can refer to the PBIX in the following drive link https://drive.google.com/file/d/1zwmulRDtPdA766Q6ixruYKDVFR6jddu-/view?usp=share_link From Table relationship perspective, sales is a fact table, while date is a dimension / date table. Thank you everyone for your time investment in attempting to help me Cheers ARUSolved4.8KViews1like10CommentsTo Help understand DAX MEASURE | RANKX | Filter Context | Row Context
I am not sure how to debug or search this below issue. My Requirement in SQL : With Members_max as ( SELECT MemberID ,Ranked_risk ,Numerator ,row_number() over (partition by memberid order by Ranked_risk ASC) as Rn from FactPatient WHERE QMID in (10,11,12,13) and Year in (2022) ) Select sum(Numerator) as Numerator -- A measure for Numerator , Count(Memberid) as Denominator -- A measure for Denominator from Members_max m where m.rn = 1 Now what I am trying to do is 1. Get the Lowest Ranked Risk for each patient for the selected months (User can select One month, Multiple Months or without any filter on Date table.) 2. Fact Patient has One Entry for each member for all months with their ranked risk (Values like 1, 2,3, .etc.), Numerator will have 0 or 1. Here is the DAX measure which is working as expected without any filters VAR QM2_data = FILTER ( FactPatient, FactPatient[QMID] IN { 10, 11, 12, 13 } ) VAR QM2_Dataset = ADDCOLUMNS ( QM2_data, "Rn", RANKX ( QM2_data, FactPatient[Ranked_Risk],, ASC, SKIP ) ) RETURN SUMX( FILTER ( QM2_Dataset, [Rn] = 1 ) ,FactPatient[NUMERATOR] ) The measure is not working as expected when we apply any filter on Date table. Data sample: Member ID Ranked Risk Numerator Month QMID 1 2 0 2022-10-31 10 1 1 1 2022-09-30 11 1 3 1 2022-08-31 11 2 1 1 2022-09-30 10 2 2 0 2022-08-31 10 3 1 0 2022-08-31 11 3 2 0 2022-07-31 11 Case 1 : When No filter applied, it is expected to pick the lowest ranked risk for each member that would be the below table MemberId Ranked Risk Numerator Date QMID 1 1 1 2022-09-30 11 2 1 1 2022-09-30 10 3 1 0 2022-08-31 11 and the dax measure for numerator would yield a value of 2. Issue part: Now, if we select a month let's say August, 2022. I was in an assumption that Numerator will be 1 after filter the dataset to Aug, 2022 and then do a ranking to arrive at following temp table tbale to do the sumX. Member ID Ranked Risk Numerator Month QMID 1 3 1 2022-08-31 11 2 2 0 2022-08-31 10 3 1 0 2022-08-31 11 But Dax expression is not evaluated on top of current filter context(Aug,2022), instead the current filter context is only applied in the last step to filter the data(Bolded) after getting the Numerator value for each month i.e in our example Month Numerator Oct, 2022 1 Sep, 2022 1 Aug, 2022 0 Thus getting Zero as value rather than 1. Summary: I want this DAX expression to calculate the rank on top of current filter expression and do the some. Could anyone help me get to understand what am I doing wrong?Solved4KViews0likes18CommentsMeasure calculation using row context
Hi; I am try to calculate a measure NumDaysOpenShop, in a Period Year/Month and in a Shop or in all shops LIke page filters i have got a Year and a Shops, in the year i can select only one, in the shop i can select one, some or all shops. In matrix i show year/month on rows 2022 Measure be SUM([Table][Colum]) with dates in 2022 and shop selected in page filter, except if all or more than one shop is selected, in this case i want use MAX(measure [NumDaysInMonth] with dates in 2022 January SUM([Table][Colum]) with dates in January 2022 and shop selected in page filter, except if all or more than one shop is selected, in this case i want use MAX(measure [NumDaysInMonth] with dates in 2022 Hope i explained .......457Views0likes0Comments