Power Bi Matrix divide column A by corresponding value from another column B and not the total of B

筅森魡賤 提交于 2020-06-01 06:57:23

问题


I am working on a multi-tab dashboard for commercial stores related variables with a star schema. I have many tabs which all feed from different tables and are all linked through a table ("Slicer_table") that feeds the slicer in every tab and is related to each table through a key of a concatenation of descriptive variables of the stores.

In one of those tabs, I calculate a rate between some event and the total number of clients. For this calculus, I use 2 tables, one which feeds all the other visuals that have the number of events ("Store_events_) and a helper table that has the client number ("stock_suc_events"). The relationship between the tables is like this:

data model

Slicer_table links with stock_suc_events by a key which is a concatenation of descriptive variables of the store as mentioned and stock_suc_events links with store_events_ with another key which is the same as the prior one plus the date.

The data in the client number table (stock_suc_events) consist of 5 registers per month of the sum of all the client numbers per key. This is 4 for each week and 1 for the month. So the same value is repeated 5 times. The reason to do this is that if it's not done this way I haven´t been able to keep all the rows in the number of event table (store_events_) because I have records of events for each week. The sum of the number of clients is calculated as a measure as this:

tot_stock= SUMX(
                DISTINCT(
                         SELECTCOLUMNS(stock_suc_events;
                                       "id";stock_suc_events[Date_key];
                                       "stock"; stock_suc_events[num_clients]
                                      )
                         );
                [stock])

A distinct is done so I only consider one value per all the 5 repeated records.

When this was created like this, we were only calculating a single rate like this:

Rate of events = (num_events* multiplier/tot_stock)*10000

with a multiplier that will help correct the rate number in case we were showing the data weekly (it just multiplies the number of events by 4.3 so it will have a value similar to what it would have if we had considered the sum of the event for all the month).

The problem came when we tried to get the rate store wise in a matrix. When I put that rate in a matrix where each row is a store, instead of getting the rate calculated as number of events per store / number of clients per store we got the number of events per store / the sum of all clients in all the stores. This is an image of what we are getting (rate) and what we would like to obtain the Corrected rate.

Current and expected output:

I have gone through many posts that use row, allexcept, filter, early, creating variables. I recently found a post that used lookupvalues to link the 2 tables but the column I created returned empty. I have no clue how to solve this. Please help!

来源:https://stackoverflow.com/questions/61862593/power-bi-matrix-divide-column-a-by-corresponding-value-from-another-column-b-and

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