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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rs1249
Helper I
Helper I

How to conditional relate to another table

Dear all,

Could someone help me with this please:

I have two tables: "Detailed_Cust_Ledg" and "Cust_Ledg", they are linked by one to many relationship with Cust_Ledg[Entry_No]-> Detailed_Cust_Ledg[Cust_Ledger_Entry_No], 1->*

 

Now I would like to create a calculated column in Detailed_Cust_Ledg[Index], with DAX something like:

Index = if([Entry_Type]="Initial Entry",RELATED(Cust_LedgerEntries[Index]), #else use the same Cust_LedgerEntries[Index]) that belongs to same [Document_No] with [Entry_Type]="Initial Entry"#)
I just can't figure out how to do the else statement in there, driving me nuts, would much appreciated if anyone can help, here are the two tables:
Detailed_Cust_Ledg
Entry_NoPosting_DateEntry_TypeDocument_TypeDocument_NoCustomer_NoAmountCust_Ledger_Entry_NoAppliedDocNoIndex
99606/12/2017Initial EntryPaymentBANK-0000365C0000050-4327861BANK-0000365#ERROR
99706/12/2017ApplicationPaymentBANK-0000365C0000050-4327680INV-0000299#ERROR
99806/12/2017ApplicationPaymentBANK-0000365C00000504327861BANK-0000365#ERROR
196814/02/2018Initial EntryPaymentBANK-0000594C0000050-12010979BANK-0000594#ERROR
196914/02/2018ApplicationPaymentBANK-0000594C0000050-1207100INV-0000205#ERROR
197014/02/2018ApplicationPaymentBANK-0000594C000005012010979BANK-0000594#ERROR
199022/02/2018Initial EntryPaymentBANK-0000594C0000050-336011005BANK-0000594#ERROR
199122/02/2018ApplicationPaymentBANK-0000594C0000050-16805717INV-0000065#ERROR
199222/02/2018ApplicationPaymentBANK-0000594C0000050336011005BANK-0000594#ERROR
199322/02/2018ApplicationPaymentBANK-0000594C0000050-16806873INV-0000140#ERROR
199707/03/2018Initial EntryPaymentBANK-0000595C0000050-34211009BANK-0000595#ERROR
199807/03/2018ApplicationPaymentBANK-0000595C0000050-3427010INV-0000183#ERROR
199907/03/2018ApplicationPaymentBANK-0000595C000005034211009BANK-0000595#ERROR
 Cust_Ledg
Entry_NoCustomer_NoPosting_DateDue_DateDocument_TypeDocument_NoAmountIndex
7861C000005006/12/201706-Dec-17PaymentBANK-0000365-432BANK-000036506/12/2017C0000050STRIPE PAYMENTS UK E-01461432
10979C000005014/02/201814-Feb-18PaymentBANK-0000594-120BANK-000059414/02/2018C0000050STRIPE PAYMENTS UK120
11005C000005022/02/201822-Feb-18PaymentBANK-0000594-3360BANK-000059422/02/2018C0000050BARCLAYS BANK PLCP3360
11009C000005007/03/201807-Mar-18PaymentBANK-0000595-342BANK-000059507/03/2018C0000050STRIPE PAYMENTS UK342
1 ACCEPTED SOLUTION

@rs1249 

you can try this

Column = 
 if(Deatiled_Cust_Ledg[Entry_Type]="Initial Entry",LOOKUPVALUE('Cust_Ledg'[Index],Cust_Ledg[Entry_No],'Deatiled_Cust_Ledg'[Cust_Ledger_Entry_No]))

Column 2 = 
if(Deatiled_Cust_Ledg[Column]="", maxx(FILTER('Deatiled_Cust_Ledg','Deatiled_Cust_Ledg'[Document_No]=EARLIER(Deatiled_Cust_Ledg[Document_No])&&Deatiled_Cust_Ledg[Entry_No]<=EARLIER('Deatiled_Cust_Ledg'[Entry_No])&&Deatiled_Cust_Ledg[Column]<>""),Deatiled_Cust_Ledg[Column]),Deatiled_Cust_Ledg[Column])

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ryan_mayu
Super User
Super User

@rs1249 

it looks like there are not matching entry number, 

 

 if([Entry_Type]="Initial Entry",RELATED(Cust_LedgerEntries[Index]) will return empty for the column

 

what's the expected output based on your sample data?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Guys, the relationsship is Detailed_Cust_Ledg[Cust_Ledger_Entry_No]->Cust_Ledg[Entry_No] *->1

on the top table the 7th Column is matched to botton table 1st column, so the end result should be in the top table last column, it should pulling in the index value from the bottom table index column, but it looks at the top table's 3rd column "Entry_Type" and 7th Column "Cust_Ledger_Entry_No", doing something like this:

If 3rd column [Entry_Type] value is "Initial Entry" Lookup (Cust_LedgerEntries[Index]) base on 7th Column "Cust_Ledger_Entry_No", if not, copy the  same Cust_LedgerEntries[Index]) that is above until the next [Entry_Type]="Initial Entry"

Hope that make sense

@rs1249 

you can try this

Column = 
 if(Deatiled_Cust_Ledg[Entry_Type]="Initial Entry",LOOKUPVALUE('Cust_Ledg'[Index],Cust_Ledg[Entry_No],'Deatiled_Cust_Ledg'[Cust_Ledger_Entry_No]))

Column 2 = 
if(Deatiled_Cust_Ledg[Column]="", maxx(FILTER('Deatiled_Cust_Ledg','Deatiled_Cust_Ledg'[Document_No]=EARLIER(Deatiled_Cust_Ledg[Document_No])&&Deatiled_Cust_Ledg[Entry_No]<=EARLIER('Deatiled_Cust_Ledg'[Entry_No])&&Deatiled_Cust_Ledg[Column]<>""),Deatiled_Cust_Ledg[Column]),Deatiled_Cust_Ledg[Column])

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.