How to pick up column by given parameters and then sum-up the column total in Power BI

杀马特。学长 韩版系。学妹 提交于 2019-12-25 01:25:01

问题


I've got a table like below. I would like to pickup the column first by given parameters then sum up the total of the column.

For example, by given Parameter of SGD, I would like to sum-up the total amount of column SGD.

Date     SO NO. AUD         SGD             HKD
7/1/2019    SO1 100      105.17          545.74 
8/5/2019    SO2 130      122.01          691.13 
9/9/2019    SO3 160      150.32          853.55 
9/15/2019   SO4 180      169.11          960.25 

Thanks


回答1:


One way to achieve this is to add a new disconnected table Currencies with one column Currency and values AUD, SGD and HKD. Add a slicer for it and make it drop down.

Then create a measure, which will take the value of the slicer and calculate total on the corresponding column, depending on the selection in the slider:

Total = SWITCH(SELECTEDVALUE('Currencies'[Currency]; "AUD");
    "AUD"; SUMX('Table'; [AUD]);
    "SGD"; SUMX('Table'; [SGD]);
    "HKD"; SUMX('Table'; [HKD]);
    SUMX('Table'; [AUD]))

SELECTEDVALUE('Currencies'[Currency]; "AUD") will return the value selected in the slicer, or AUD if none or multiple values are selected. See SELECTEDVALUE.

SWITCH will compare this value with a list of possible options (AUD, SGD and HKD) and return corresponding expression (SUMX('Table'; [AUD]), SUMX('Table'; [SGD]) or SUMX('Table'; [HKD])), or some default value if there is no match (SUMX('Table'; [AUD])).

Then use this measure in your report, and it's value will change depending on the selection in the slicer:



来源:https://stackoverflow.com/questions/58369013/how-to-pick-up-column-by-given-parameters-and-then-sum-up-the-column-total-in-po

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!