Forum Discussion
Top N for Many Columns in Table
- Anonymous2 years ago
Hi gigaenvy ,
Your first syntax is logically correct, which is great!
Your second syntax is a little wrong, here is the revised one:
Top_10_Failed = VAR TopNValue = 10 VAR FailedTable = UNION( SELECTCOLUMNS(FILTER(PatientCheck_InspAnswers, PatientCheck_InspAnswers[HeartO] = "Failed"), "Item", "HeartO", "Count", [Failed_LCD1]), SELECTCOLUMNS(FILTER(PatientCheck_InspAnswers, PatientCheck_InspAnswers[HeartL] = "Failed"), "Item", "HeartL", "Count", [Failed_LCD2]) // Repeat for each measure/column... ) VAR RankedTable = ADDCOLUMNS(FailedTable, "Rank", RANKX(ALL(FailedTable), [Count], , DESC, Dense)) RETURN FILTER(RankedTable, [Rank] <= TopNValue)Please change the underlined [Failed_HeartO) to [Failed_LCD1], and so on, change [Failed_HeartL] to [Failed_LCD2]...
Please add the ALL function to the underlined FailedTable to prevent it from possible context filtering effects.
Please try the modified syntax. If it does not work, I would be grateful if you could provide me with the pbix file or sample data.
Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hi gigaenvy ,
Your first syntax is logically correct, which is great!
Your second syntax is a little wrong, here is the revised one:
Top_10_Failed =
VAR TopNValue = 10
VAR FailedTable = UNION(
SELECTCOLUMNS(FILTER(PatientCheck_InspAnswers, PatientCheck_InspAnswers[HeartO] = "Failed"), "Item", "HeartO", "Count", [Failed_LCD1]),
SELECTCOLUMNS(FILTER(PatientCheck_InspAnswers, PatientCheck_InspAnswers[HeartL] = "Failed"), "Item", "HeartL", "Count", [Failed_LCD2])
// Repeat for each measure/column...
)
VAR RankedTable = ADDCOLUMNS(FailedTable, "Rank", RANKX(ALL(FailedTable), [Count], , DESC, Dense))
RETURN FILTER(RankedTable, [Rank] <= TopNValue)
Please change the underlined [Failed_HeartO) to [Failed_LCD1], and so on, change [Failed_HeartL] to [Failed_LCD2]...
Please add the ALL function to the underlined FailedTable to prevent it from possible context filtering effects.
Please try the modified syntax. If it does not work, I would be grateful if you could provide me with the pbix file or sample data.
Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
- gigaenvy2 years agoFrequent Visitor
Thank you for the reply and follow up. Give me some time to play with before replying or Accepting the solution. Nag me next week if I forget 🙂