in Dax, how do I row match by some categorical column instead of getting a single value when using a numerical variable from another related table - powerbi

How can I use the values of a variable from a table B in a related table A in a such a way that it can be matched to each row of table A correspondingly?
I need to calculate a ratio as this
sum(A[event_number])/sum(B[client_number]
The 2 variables are from different related table. The relation between the tables are one (A) to many (B).
When I put this ratio on a matrix constructed with variables and measures from table A where the rows are stores, the denominator should be the client number per store but I only get the sum of all clients instead.
For example if a store "ASD" has 5 events it should get divided by 20 which are the clients related to that store and not 500 which is the sum of all clients for all stores.
I have tried using related when calculating the ratio, and allexcept to create a column of number of clients in A but nothing has given the expected result. Please help.

Related

PowerBi- Prevent slicer from filtering a table returned measure

I will do my best to explain this correctly. I have a data set that has 4 category columns (Date, Store, Provider, Pick Location) and 4 value columns (Total Orders, Total Deliveries, Accepted Deliveries, Assigned Deliveries). Please see the image here:
The two total columns should be grouped by date and store and have the same value regardless of the provider or pick location - There is the potential to see the same value up to 4 times depending on the category combination. The final two value columns will be different for every line and should not be grouped.
The issue I am facing is to be able to:
Sum up the total columns by the date/store group to ensure there is no duplication
Sum up the other value columns NOT by the date/store group without affecting the totals
Have the total columns be only affected by the Date and Store slicer (NOT the Provider and Location)
Have the other values filter as normal for all slicers
Ultimately calculate percentages of "total" based on the affected slicers.
Here is a visual summary of what I would be trying to accomplish:
Currently, I have been able to create a "sum of averages" to allow the total values to display correctly based on the date and store, but am unable to get it to ignore the provider and location slicer:
total_pro_orders_f = var _table=SUMMARIZE(md_pbi_datafile,md_pbi_datafile[date], md_pbi_datafile[store_number],"_orders", averagex(md_pbi_datafile, md_pbi_datafile[total_pro_orders]))
RETURN
calculate(SUMX(_table,[_orders]), REMOVEFILTERS(md_pbi_datafile[lpName],md_pbi_datafile[transaction_is_sourced]))
I have tried all the different ignore filter commands I could find but no matter what I do I cannot get the totals to stay the same regardless of provider or location.
Does anyone have any advice on how to accomplish this?
Thank you all!

Divide two measures from two different tables

I have to divide two measures from two different tables. I have created a measure in Table A & created measure-2 in Table B.
When I use matrix visual in Power BI by taking date field in columns and region in rows (for table A&B), I can see the both table values are correct as I am expected.
Ex: Table A 2017-Q1 value by measure1 is 29.2, Table B 2017-Q1 value by measure1 is 2.9.
I have to divide both measures and I need to show the value (divide%) in TableA along with Measure1.
Unfortunately I tried in multiple ways by forming relationship b/w two tables also, But not getting the expected result i.e., 29.2/2.9 we should get 10% but instead of that getting 3%.
Without knowing your data model, it's hard to give a reasonable answer.
https://learn.microsoft.com/en-us/dax/related-function-dax
Your best change of understanding what happens is to learn up on relations, and changes them when needed. The documentation is a great starting point.
Unrelated data plotted in a visual of different data will always aggregate since there is no relation to split your values. The value of 3% is correct, your assumption that you want 10% as an outcome is not valid for your situation.
If you link the dates of table A and the dates of table B to a seperate Calendar, it all would work.

Calculated column in Power BI that repeats different sums based on conditions in 2 other columns

I need a calculated column based on conditions in two columns (Business Unit Number in both tables and L1/Account Categories in 1st table and the second table) which sum and then repeat for several rows before the conditions change and a new sum is repeated for several rows and so on. The L1/Account Categories columns have different names because it's the raw data.
For example, any time ASSETS and 111 appear in the same row, I would want to use those as conditions and with the sum of all of the other matching rows in a new column and the sum would repeat each time both conditions appeared in the same row. Any time P/L and 111 appear in the same row, that would be a sum of all other P/L and 111 appearances in the dataset (about 1000 rows overall)... and so on.
I've tried formulas with DAX using FILTER, SUMX, nested IF statements and also tried the Power Query language among other attempts. Maybe I have to create one or more than one new table? If you need to take a look at a few of my attempts, just let me know.
The top image is how I imagine the output will look in the power query editor and the bottom image is a sample of the source data.
This last pic is from Tableau - I need to make a table in Power BI which essentially a duplicate of this image. The last 2 columns are pulling from different tables.
This should be very simple to achieve with relationships and measures - no need for calculated columns or power query merges. You need to build a relationship between these two tables. In fact, I would introduce a third table in your model for Business unit.
The limitation of Power BI model relationships is that they can only be based on a single column. So to build a relationship between these two tables you would have to add a calculated column in both of them that would contain both a BU and the financial statement line, for instance: JoinCol = CONCATENATE([Business_Unit_Number], [L1]). Then you could create a relationship and do what you want.
The better (one that I would recommend) approach would be to separate Business Unit into a separate table and have relationships built like this:
Then all you have to do in your visual is drag Business unit name from the BU table, L1 from the FS Lines table and a measure to sum the amounts Amount = SUM('Financial Data'[Rolled Up Detail]).
Here is a working sample: https://1drv.ms/u/s!AmqvMyRqhrBpgtUT5HKnZP1U3Gzc9w?e=en91dV

Power BI - Extract / Moving value to a separate column

I have a column that includes 2 different values for more than 100k customers
The values are: "Consumer" , "SMB"
How can I move "SMB" values to a separate column ? I want each value to be shown in a different column so I can use KPI for each one of the values.
For ex: I want to create 2 different KPIs, one for SMB and 1 for Consumer, which show how money in total each segment has been charged.
When you load the data in the Power Query editor, use the command to split the column with the values. Use the comma as the delimiter.

Power Bi Desktop - How to add values between tables?

I'm trying to create a column that has a total of values between 3 columns from 3 tables. How would I go about doing this?
The 2 tables are tables of values that share an id, and they are both linked to a table of account by Id. The goal is to add up 3 columns, and place it into a table grouped by the Id.
I've attempted summing them, trying to use the USERELATIONSHIP function, and creating a relationship between them. It seems to give very inaccurate results, as if it's summing all of the totals together, and passing them to each Id. That, or it won't let me use the column, as if it never existed.
EDIT: General Idea of what I'm trying to do (Lines should be pointing to Account's Id column, but I messed up the lines)
EDIT 2: I also forgot to illustrate or mention. There are more columns with information in each table that can't be summarized for each account preventing me from just merging the table together.
Make sure your data model looks like this (change names as you please, but the structure must be the same):
In dimensional modeling, your table "Account" is a Dimension, and both fee tables are Fact tables. The operation of combining data from multiple fact tables that share the same dimension is called "drill-across", and it's a standard functionality of Power BI.
To combine fees from these tables, you just need to use measures, not columns. This article explains the difference:
Calculated Columns and Measures in DAX
First, create 2 measures for the fees:
Fee1 Amount = SUM(Fee_1[Amount])
Fee2 Amount = SUM(Fee_2[Amount])
Then, create a third measure to combine them:
Total Fee Amount = [Fee1 Amount] + [Fee2 Amount]
Create matrix visual, and place Account_ID from the Account table on the rows. Then drop all these measures into the matrix values area, like this:
Result:
Of course, you don't have to have all these measure in the matrix, I just showed them for your convenience, to validate the results. If you remove them, the last measure still works: