Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
win_anthony
Resolver III
Resolver III

Advice Needed: Data Modeling / Table Relationship

The goal is to have each transaction reflect a location that is associated with it. Each transaction is housed in a fact table and can be identified with a location through 2 columns: Owner / Entity. A Location dimension table was created and is connected to the transaction fact table through the store number. Problem is that when a transaction is identified by a district (district is 1 hierarchy level higher than store), I cannot get the associated transaction to reflect the district. Only specific transaction items will reflect the district as the location. It is ok that there is no store number associated with certain entities (ex: TACOS + BURGERS), the goal is to have the district number reflected if the entity reflect's district. Below you will find sample data for context: Location dimension table / current fact table data output / expected fact table data output. I know that my current set up is expected and the missing data (district number) would not show but how would you approach this if the requirement is to have it reflected? 

 

Any advice will be greatly appreciated. 

 

Location Dimension Table: This dimension table is linked to the fact table via Store_Number

DistrictDistrict_NumberStoreStore_Number
Seattle (00101)10110001 - 1 Seattle St. Seattle, WA10001
Los Angeles (00102)10210002 - 2 Los Angeles Blvd. Los Angeles, CA10002
Austin (00103)10310003 - 3 Austin Dr. Austin, TX10003
Chicago (00104)10410004 - 4 Chicago Ln. Chicago, IL10004
New York (00105)10510005 - 5 New York Ave. New York, New York10005

Current Fact Table Data: Notice only items TACOS + BURGERS does not have a district number being reflected. 

trans_iditemdistrict_numberstore_numberentityowner
1Pizza10110001Pizza HutStore Manager 10001
2Sushi1011000110001 - 1 Seattle St. Seattle, WAJoe Rogan
3Tacos  Chicago (00104)Michael Jordan
4Burgers  Austin (00103)Elon Musk
5Ramen1051000510005 - 5 New York Ave. New York, New YorkStore Manager 10005

Expected Fact Table: Notice that items TACOS + BURGERS now reflect the district number. It is ok that there is no store number associated with TACOS + BURGERS, the goal is to have the district number reflected if the entity reflect's district. 

trans_iditemdistrict_numberstore_numberentityowner
1Pizza10110001Pizza HutStore Manager 10001
2Sushi1011000110001 - 1 Seattle St. Seattle, WAJoe Rogan
3Tacos104 Chicago (00104)Michael Jordan
4Burgers103 Austin (00103)Elon Musk
5Ramen1051000510005 - 5 New York Ave. New York, New YorkStore Manager 10005

Current Data Model

datamodel.png

2 ACCEPTED SOLUTIONS

You definitely want to use the DIM table, but there is no way I can see to relate them.

edhans_0-1647629510618.png

In your top table, Taco/Burgers have no district or store. So how woudl they relate to a dim table. My offered advice was to populate the district in Power Query since the district seems to be embedded in the customer location - Chicago (00104) is district 104 per your 2nd fact table.

 

What am I not understanding?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

@edhans thank you again for your support! Truly appreciated. I think you answered it for me. There is probably no possible connection for me to create by using the DIM table. I was hoping for some sort of workaround where I would be able to have the DIM[District Number] reflected on a table. 

 

Once again, thank you so much for your support!

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

You should use Power Query to put the district number there from the entity name.

if [district_number] = "" or [district_number] = null 
then 
   Text.TrimStart(
       Text.BetweenDelimiters([entity], "(", ")"),
       "0"
    ) 
else [district_number]

When done it looks like this:

edhans_0-1647624212930.png

Full code is here.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZDRCsIwDEV/JfRJYcqm7gOmCCJMxAkiYw9hhq1sttC1Cn69sdP5oFB6k9uccGmei0gEYi8fD2SNwsjfYTi4sHGW68xqQ5CiwooM9BNFkIvZ6811tfyhvcIEIsgIrW0JMjv91AGcEp7ZaoKDrlD5XXN2jljqjrU/q1qWWGkY8apwMWYnlWWN1MJWm8sbW7C9dIZzfcHEdVaqnpu/uHWrFaSuazwSs3PAKymfM36nHZRTx7CjO5y1aSC50XTogqH6+ymxKIon", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [trans_id = _t, item = _t, district_number = _t, store_number = _t, entity = _t, owner = _t]),
    #"Added Custom" = Table.AddColumn(Source, "New District Number", each if [district_number] = "" or [district_number] = null 
then 
   Text.TrimStart(
       Text.BetweenDelimiters([entity], "(", ")"),
       "0"
    ) 
else [district_number]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"district_number"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"New District Number", "district_number"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"district_number", type text}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type",{"trans_id", "item", "district_number", "store_number", "entity", "owner"})
in
    #"Reordered Columns"

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans thank you so much for your support! Question, are you suggesting that I do not use my Location dimension table? What I failed to mention is that my source SQL query yes has the District Number parsed out. Problem is that when I drop the Dimension District Number column into a table, the District Number is NULL. My Fact table does have the district number. 

 

The goal is to use the dimension table and have the district number column be reflected like shown in the expected output. All of this may be confusing but I hope you understand. Please let me know your thoughts. 

You definitely want to use the DIM table, but there is no way I can see to relate them.

edhans_0-1647629510618.png

In your top table, Taco/Burgers have no district or store. So how woudl they relate to a dim table. My offered advice was to populate the district in Power Query since the district seems to be embedded in the customer location - Chicago (00104) is district 104 per your 2nd fact table.

 

What am I not understanding?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans thank you again for your support! Truly appreciated. I think you answered it for me. There is probably no possible connection for me to create by using the DIM table. I was hoping for some sort of workaround where I would be able to have the DIM[District Number] reflected on a table. 

 

Once again, thank you so much for your support!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.