Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi.
Here is my data tables:
"Datagrunnlag" is the fact table. which contains many transactions which are registered on both company code and project code. I then have 10 more columns with information in two different dim_tables (dim_prosjekt and dim_selskap (company)), the same columns exist in both dim_tables, however one dim_table (dim_prosjekt) also conaints more information. The fact table (datagrunnlag) is linkes to the two dim_tables with company_ID and project number.
On some companies i have registered the "tags" in the "dim_selskap" table, but for other companys the tags need to be done by project number. So in this companies the "tags" are registered in the dim_prosjekt table.
What i need to do now is to merge this 10 data fields from the dim_tables together to 10 new colums in the fact Datagrunnlag table, so that i can get complete values in the fact table.
I have searched for different solutions, by conditional merge, and i also found this topic:
https://community.powerbi.com/t5/Power-Query/Conditional-Merge/m-p/844207#M28332
This seemed like a good solution:
However that would be easy with 1 column. But now i have 10 colums (which could be more later). I then realised i had to to this calculations for each column, and also add do it manually again if i get more colums in the dim_tables. So i tried another solution:
It seems like this should work, because the new custom column seems to give me a new table in the new colum. However i struggle to find the right if formula when i add the custom colum.
So after i have done the two merges i have the two new table colums:
if [#"dim_selskap (z-ark)"] is null then [#"dim_prosjekt (z-ark)"] else [#"dim_selskap (z-ark)"]
Which is obviously wrong. But it gives me a new cusom column with table. The table is always from dim_selskap, because the "is null" part is wrong. But since it gives me a table i was hoping this could work.
What i was hoping to do was to change the formulat to something like this:
if "[#"dim_selskap (z-ark)"].column(use_project_relation) is "Yes" then [#"dim_prosjekt (z-ark)"] else [#"dim_selskap (z-ark)"]
The.column part is wrong, i dont know what to write to get this to work. Or if it would work at all. Hope someone could guide me in the right direction. Would this work or is it better to do it another way?
Thanks
Hans Petter
Solved! Go to Solution.
Ok, i think i finally understood what you meant.. I now did this:
I now have a relationship with all values, which was what i wanted, and the refresh on the dataset takes 15 seconds instead of 15 minutes 🙂
Now i just need to find out how i can combine relationships, which can change over time.. so that the releationship is different lets say in 2020 than it is in 2021...
Yes. Send two versions so we can see the dynamic column structure change.
Hi, i sent you the model in a private messag, did you receive it?
I did. Haven't had enough time to think about it. Maybe over the weekend. Work is crazy at the moment.
Ok, i think i finally understood what you meant.. I now did this:
I now have a relationship with all values, which was what i wanted, and the refresh on the dataset takes 15 seconds instead of 15 minutes 🙂
Now i just need to find out how i can combine relationships, which can change over time.. so that the releationship is different lets say in 2020 than it is in 2021...
Dont worry about it, just happy that you take the time to help a poor guy.
I would construct the additional tables in Power Query. That way you can shape them dynamically (with the columns you need) and use them in the Power BI data model for your hierarchies.
Thank you but i have a little trouble to understand what it the outcome of this. Could you explain in more detail?
Maybe hard to explain. If i send you my datafile could it be easier to show me?
Found a solution myself:
Power Query has functions to get table columns. If your first row are the header columns then you grab that and then use it for the expand transform.
Yeah that was what i was trying to do yesterday, but i did not know the right formula 🙂 However expanding the column and then doing the if formula bases on column value seems to work.
The only thing is that the expanding column is making my datamodel take forever to update... Thats with 30000 rows of data. It takes maybe 10-15 min to update. Didnt know this function was that slow. Vlookup in excel does this in seconds on the same data 😕
@Hanspw wrote:
Yeah that was what i was trying to do yesterday, but i did not know the right formula 🙂 However expanding the column and then doing the if formula bases on column value seems to work.
The only thing is that the expanding column is making my datamodel take forever to update... Thats with 30000 rows of data. It takes maybe 10-15 min to update. Didnt know this function was that slow. Vlookup in excel does this in seconds on the same data 😕
Power Query Merge is one of the costliest operations as it kills both the preview and the query folding. That is why I suggested using additional dimension tables instead.
Ok thanks, good to know. Could you possible try to explain how i can use additional dimension tables instead of doing the merge? The goal would be that i need to combine those dimensions fromt he two dim tables, into a combined field which i can use in my reports.
In excel i did this by a combination of if fomula and vlookup from the two tables.
@Hanspw this is an interesting problem.
Can you please try the following for a fully dynamic conditional merging solution
//tableName-dim1
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7PLTBU0lFKycw1VIrVgQgYQQSMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [comp = _t, dim = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"comp", type text}})
in
#"Changed Type
dim1
//tableName-dim2
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7PLTBW0lFKycw1VorVgQiYQARMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [comp = _t, dim = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"comp", type text}})
in
#"Changed Type"
dim2
//output
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7PLTBUitWBsIzgLGM4y0QpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [comp = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"comp", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "fromdim1", each List.Contains(dim1[comp],[comp])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "formdim2", each List.Contains(dim2[comp],[comp])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom", each if [fromdim1]=true then dim1 else dim2),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom.1", each let
val= [comp],
x = [Custom],
y = Table.SelectRows(x, each([comp]=val)),
z = Table.SelectColumns(y,{"dim"})
in
z),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom3",{"comp", "Custom.1"}),
#"Expanded Custom.1" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom.1", {"dim"}, {"dim"})
in
#"Expanded Custom.1"
master
in
"
What i need to do now is to merge this 10 data fields from the dim_tables together to 10 new colums in the fact Datagrunnlag table, so that i can get complete values in the fact table."
Or you could add more dmension tables and let the data model do the work for you.
Could you elaborate what you mean here? Do you mean to combine the two dim tables to a new dim table or something else? I dont see how this would solve my problem to get "one" complete relation to the fact table?
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
70 | |
63 | |
40 | |
28 | |
15 |