minx
12 TopicsFlag to mark two lowest values from Table. Grouped by other columns
Hello, I am using table in direct query mode as source. Table shows active users already grouped per Month, country, User_Tier, User_Group for last 12 weeks. Example below. Example table is smaller, but by default each month based on Month_Key has 12 Reported_weeks. Combinations of possible User_Tier, User_Group differs - so it may be 1 row per Reported_week or 5 tows per reported_week. Country Month_Key Reported_Week USER_TIER User_Group Weekly_Users_Count PT 20240901 202428 A H 20 PT 20240901 202428 B J 10 PT 20240901 202429 A H 30 PT 20240901 202429 C H 20 PT 20240901 202430 B J 10 PT 20240901 202430 C H 30 FR 20240901 202428 B G 50 FR 20240901 202428 B T 40 FR 20240901 202429 A G 100 FR 20240901 202429 A G 55 FR 20240901 202430 A G 66 Currently there is a measure that caluclates a Weekly number of active users by: # Weekly Active Users = Calculate(Divide(Sum(Table[Weekly_User_Count]),12)) Is there a possibility at DAX level to change the calculation to take only 10 weeks with best values for each month and country? So basicly Flag two worst Reported_Week (sum of all combination of User_Tier, User Group). I tried do it two ways and failed: Idea #1 - FAILED - Create Dax measure to detect lowest values. I used "MIN" Idea #2 - FAILED - Create a calculated Column to mark rows with lowest values. Again failed, aiming to use "EARLIER" Thank you gor helpSolved587Views0likes2CommentsHow can I return only the third highest/lowest category as a measure?
[Edited please see sample file here] Hello! I'm using this measure to get the item that received the most and least ordered: Items Sold = COUNT(Orders[order_id]) MostSoldItem = CALCULATE( VALUES(Menu[item_name]), FILTER( ALL(Menu[item_name]), [Items Sold] = MAXX(ALL(Menu[item_name]), [Items Sold]) ) ) LeastSoldItem = CALCULATE( VALUES(Menu[item_name]), FILTER( ALL(Menu[item_name]), [Items Sold] = MINX(ALL(Menu[item_name]), [Items Sold]) ) ) These measures work, but now I want to find the third item that received the most orders, as well as the third item that received the least orders. I created a Rank measure to help me achieve this: ItemRanks = CALCULATE(RANKX(ALL(Menu[item_name]),[Items Sold],,DESC)) But I'm not sure how I can use this measure to help me return what I want. Please help! Thank you.Solved841Views0likes3CommentsGet a corresponding price from another table using relationship through item table
Hi! I have this pretty complex problem (at least for me) that I can't seem to solve by myself. So basically I have this table called "Latest purchase price", which has information about every items latest purchased. I also have an item table and then I have a trade agreements table that contains information about every item's trade agreements for different purchase quantities, thus the relationship between that table and item table is many-to-one. I'll post a picture here about the data model if that helps. I want to compare latest purchase price to the price that we have in trade agreements thus I need to get the corresponding value from the trade agreements table for the latest purchase. I'll post a mockup data here also so that you can try it yourself. I have tried to do this using summarize columns and sumx. The logic is that once I have the virtual table with trade agreements for given item, I can use filter condition to filter it only contain values where purchased qty is equal or greater than fromqty in trade agreements table. Still it is ambiguous so using minx I want to just get one value which should be correct. But as you can see from picture bellow my dax query is not working... Trade agreement price = var latest_qty = MAXX('Latest Purch Prices', 'Latest Purch Prices'[OrderedQty]) var trade_agreement_qty = FILTER(SUMMARIZECOLUMNS( vDimItem[ItemID], TradeAgreements[AMOUNT], TradeAgreements[QUANTITYAMOUNTFROM]), TradeAgreements[QUANTITYAMOUNTFROM] <= latest_qty) return MINX(trade_agreement_qty, TradeAgreements[QUANTITYAMOUNTFROM]) Latest Purch Price Table: ID ITEM PRICE ORDEREDQTY 1 1234 1 1 2 1235 2 10 3 1236 11 3 vDimItem: ID ITEMID 1 1234 2 1235 3 1236 TradeAgreements: ITEMRELATION FROMQTY AMOUNT 1234 0 1 1235 0 5 1235 10 2 1236 0 10 1236 5 5 1236 10 2 Goal/Result: ID ITEM PRICE ORDEREDQTY TRADEAGREEMENT PRICE Difference 1 1234 1 1 1 0 2 1235 2 10 2 0 3 1236 11 3 2 -1Solved2.4KViews0likes2CommentsDAX measure: ID from MIN date - historical data in live connection
Hello all, This is a follow-up question from my last post: DAX measure: MIN date for historical data in live connection I have a live connection to a SQL table “Data” with historical data. Example Data: ID Status Start End Changed 1 A 2022-05-13 2022-05-13 1 B 2022-05-13 2022-05-14 2 A 2022-05-15 2022-05-15 3 A 2022-05-15 2022-05-15 2 C 2022-05-15 2022-05-16 2022-05-16 3 B 2022-05-15 2022-05-16 3 B 2022-05-15 2022-05-17 3 C 2022-05-15 2022-05-18 2022-05-18 4 A 2022-05-15 2022-05-15 4 A 2022-05-15 2022-05-16 5 A 2022-05-15 2022-05-16 6 A 2022-05-16 2022-05-16 I get the MIN Start-date with Status “A” if the corresponding ID had no other Status since then according to the following formula (all thanks to Jihwan_Kim): VAR _IDunderA = SUMMARIZE ( FILTER ( Data, Data[Status] = "A" ), Data[ID] ) VAR _IDunderothers = SUMMARIZE ( FILTER ( Data, Data[Status] <> "A" ), Data[ID] ) VAR _IDonlyA = EXCEPT ( _IDunderA, _IDunderothers ) VAR _newtable = CALCULATETABLE ( Data, TREATAS ( _IDonlyA, Data[ID] ) ) RETURN MINX ( _newtable, Data[Start] ) Result for example data: 2022-05-15 What to achieve: Now, I would like to get the corresponding ID or IDs to the MIN Start-date respectively. Expected Result: ID 4 ID 5 I tried a combination of FILTER and SELECTEDVALUE but it did not work so far. VAR _IDunderA = SUMMARIZE ( FILTER ( Data, Data[Status] = "A" ), Data[ID] ) VAR _IDunderothers = SUMMARIZE ( FILTER ( Data, Data[Status] <> "A" ), Data[ID] ) VAR _IDonlyA = EXCEPT ( _IDunderA, _IDunderothers ) VAR _newtable = CALCULATETABLE ( Data, TREATAS ( _IDonlyA, Data[ID] ) ) RETURN CALCULATE(SELECTEDVALUE(Data[ID]), FILTER(Data,Data[Start]=MINX( _newtable, Data[Start]))) Any suggestions? Thanks!Solved584Views0likes1CommentMin of Sum
Hi, how can I calculate the min values of summarized table? I tried several thing already with sumx in combination with min and summarize but still no luck. In the output table the first three columns are dimensions rest of should be calculated were the min of columns is the lowest value per Type summarized Input Table: Detail Type Size Amount 01. Straight Straight H 2 01. Straight Straight L 10 01. Straight Straight XS 10 01. Straight Straight M 2 01. Straight Straight S 6 01. Straight Straight XL 3 02. Small Small H 3 02. Small Small L 6 02. Small Small XS 3 02. Small Small M 9 02. Small Small S 9 02. Small Small XL 4 03. Straight Straight H 6 03. Straight Straight L 9 03. Straight Straight XS 5 03. Straight Straight M 6 03. Straight Straight S 9 03. Straight Straight XL 7 04. High High H 1 04. High High L 8 04. High High XS 4 04. High High M 2 04. High High S 9 04. High High XL 10 05. High High H 1 05. High High L 6 05. High High XS 6 05. High High M 8 05. High High S 8 05. High High XL 1 06. Medium Medium H 7 06. Medium Medium L 9 06. Medium Medium XS 7 06. Medium Medium M 1 06. Medium Medium S 8 06. Medium Medium XL 7 07. Straight Straight H 1 07. Straight Straight L 1 07. Straight Straight XS 3 07. Straight Straight M 9 07. Straight Straight S 1 07. Straight Straight XL 7 08. Straight Straight H 8 08. Straight Straight L 1 08. Straight Straight XS 2 08. Straight Straight M 7 08. Straight Straight S 2 08. Straight Straight XL 4 09. Small Small H 8 09. Small Small L 9 09. Small Small XS 7 09. Small Small M 3 09. Small Small S 3 09. Small Small XL 5 10. Straight Straight H 7 10. Straight Straight L 8 10. Straight Straight XS 4 10. Straight Straight M 3 10. Straight Straight S 5 10. Straight Straight XL 3 11. Small Small H 3 11. Small Small L 4 11. Small Small XS 7 11. Small Small M 10 11. Small Small S 10 11. Small Small XL 2 12. Small Small H 8 12. Small Small L 3 12. Small Small XS 3 12. Small Small M 9 12. Small Small S 3 12. Small Small XL 5 13. Small Small H 3 13. Small Small L 4 13. Small Small XS 6 13. Small Small M 8 13. Small Small S 10 13. Small Small XL 9 14. High High H 6 14. High High L 10 14. High High XS 7 14. High High M 7 14. High High S 6 14. High High XL 4 15. Medium Medium H 3 15. Medium Medium L 5 15. Medium Medium XS 4 15. Medium Medium M 6 15. Medium Medium S 4 15. Medium Medium XL 10 16. Small Small H 3 16. Small Small L 6 16. Small Small XS 6 16. Small Small M 1 16. Small Small S 3 16. Small Small XL 5 Output Table Size Type Sum of Amount Min of Delta H High 8 8 0 H Medium 10 7 3 H Small 28 28 0 H Straight 24 23 1 L High 24 8 16 L Medium 14 7 7 L Small 32 28 4 L Straight 29 23 6 M High 17 8 9 M Medium 7 7 0 M Small 40 28 12 M Straight 27 23 4 S High 23 8 15 S Medium 12 7 5 S Small 38 28 10 S Straight 23 23 0 XL High 15 8 7 XL Medium 17 7 10 XL Small 30 28 2 XL Straight 24 23 1 XS High 17 8 9 XS Medium 11 7 4 XS Small 32 28 4 XS Straight 24 23 1Solved2KViews0likes2Commentscalculate not respecting its own filter
Hoping I can get some help here. I have a measure using another measure as a filter value to try to find the earliest date for which a column equals the filter value. I'm getting strange behaviour from the peakdate measure, however. I have a table: TABLE, with columns DATECOL and INDICATOR. The date range in this table is not continuous, but spans more than a year,and ends on the current day (and there are data for that current day). I have a measure, PEAK, that finds the maximum value of INDICATOR that falls within a date range. PEAK = calculate(maxx('TABLE', 'TABLE'[INDICATOR]),'TABLE'[DATECOL]>=date(2021,12,01)&&'TABLE'[DATECOL]<=date(2022,03,01)) This measure seems to work fine - finds the peak value in that date range, and I can confirm that by visually inspecting values in the table. I have ANOTHER measure, DATEOFPEAK, that I want to return the earliest date in DATECOL which the PEAK is observed (in this case, it occurs on multiple days). DATEOFPEAK = calculate(min('TABLE'[DATECOL]),filter(all('TABLE'),'TABLE'[INDICATOR]=[PEAK]&&'TABLE'[DATECOL]>=date(2021,12,01)&&'TABLE'[DATECOL]<=date(2022,03,01)) This will not work, it returns the minimum date specified by the filter (2021,12,01) rather than the minimum date at which the PEAK value is observed in the INDICATOR column. I have ensured that the variables are formatted in the same way. In the original table (which is a calculated table, although I'm having the same problem whether my PEAK measure is based on a preexisting column, a calculated column, or a column in a calculated table), INDICATOR is rounded to 0 (in the actual column calculation in the summarize DAX command). I've tried swapping firstdate for min and I've tried restructuring as a MINX, and everything just returns the minimum date value specified in the PEAK measure but it's ignoring the part of the filter that directs it to filter INDICATOR down to only values that match PEAK. Please, what am I missing?Solved845Views0likes2CommentsMAXX and MINX calculating wrongly on measure
I've made a running total measure (Balance) to my table Transactions like this: Balance = Calculate(SUM(Transactions[AccountValue]),FILTER(ALL(Transactions[TransactionsDTM]),Transactions[TransactionsDTM]<=MAX(Transactions[TransactionsDTM]))) This one works, I've put the same data in Excel and compared cell by cell, Balance is calculated correct. Then I'try to find the Max- and Min-value of Balance like this: Balance MAX = MAXX(ALL(Transactions ),Transactions [Balance]) The expression is evaluated and returns data, but the numbers are wrong, in the order of Max supposed to be 19 millions but shows up 21 millions, Min supposed to be -60 millions, shows -90 millions. Any suggestions of where I'm failing? Regards, John MartinSolved1.9KViews0likes4CommentsUnwanted Aggregation with dynamic Ranking
Hi, I am trying to create a dynamic ranking measure. Lets say I have n rows after every filter operation. Now I want the rows enumerated from 1.. n, according to their original id (which is unique). link to pbix <- here is a reproduction of the error. Password: Example%5 I tried the solution by @Eirc_Zhang from this post but it does not work for me. Here is the code how I modiefied it, to use the index as the parameter for ranking. RankID = MINX ( FILTER ( SELECTCOLUMNS ( ALLSELECTED ( ParentData ); "index"; ParentData[Index]; "rank"; RANKX ( ALLSELECTED ( ParentData ); ParentData[Index];; ASC; DENSE ) ); [index] = MAX ( ParentData[Index] ) ); [rank] ) Everytime I use a visual with non unique field combinations, the rows are aggregated, as you can see in Visual (1) in my posted image. In Visual (2) the unique field "Index" is added and then there is no aggregation. The final goal would be to use a non unique field and the RankID togehter in a scatter plot (Visual 3). Since you can't add there another field there would be always an unwanted aggregation. Can someone help me to fix the problem? (I already managed to do it with a python visual, but I would rather have an interactive visual. I kinda wish, I could use python to calculate measures ) I actually don't fully understand the linked solution and would appreciate, if someone could help me to understand it a little better. For example I have a hard time to understand how the MINX function works, since the inner filter call just returns a table with a single row as output, as you can see in the next image. Best regards, AndreasSolved1.7KViews0likes4CommentsDAX to show Total value by Month highlighting High and Low or Max and Min data points.
Hello Community Members I'm struggling with this DAX, objective is to create a measure to show High and Low data points for total utility consumption per month. The date is coming from the date table which got Date, Year, Month of Year, Quarter of Year, Day of Month as field list. [Total Utility] is DAX measure. With this DAX, I'm aiming to achieve 1 against High and Low value by month and then with the help of conditional formatting, I highlight '1' in my Line chart or Clustered Column. But somehow my DAX is not working, Ideally i like to see 1 against the blue circled value., instead I'm only getting 1 for the highest value for the whole selected range for the year. Tried using MINX / MAXX with ALLSELECTED or SUMMARIZE and ADDCOLUMNS nothing working. My current DAX which is not giving the desired output is below mentioned. Please suggest any tweaks or new DAX. OVERALLMAXMIN = VAR ELECTRIC = [Total Electric] VAR MAXELECTRIC = MAXX(ALLSELECTED('Date'[Year],'Date'[Month]),[Total Electric]) VAR MINELECTRIC = MINX(ALLSELECTED('Date'[Year],'Date'[Month]),[Total Electric]) VAR RESULTS = IF(ELECTRIC=MAXELECTRIC || ELECTRIC=MINELECTRIC, 1, 0 ) RETURN RESULTS959Views0likes2Comments