Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to filter one table by another table

Hello,

I have the following two tables, named "Total credit" and "Invoiced amount". I am trying to find a way to filter the second table, "Invoiced amount" by Region. 

Since the "Document ID" column is common to both tables (however, not all Document ID numbers are found in both tables and they are not always unique), i tried to create a relationship between the two tables in the Model window of Power BI:

I then added the second table to a Table visualization in Power BI and added a slicer to filter by Region but it does not work.

The Document ID from the first table should be considered as the reference list, so any Document ID's not in common with the second table should be ignored. 

Any help is much appreciated!

 

Total credit:

Document IDValidityCreditRegion
399801/01/2018220HET
405001/01/2020117HET
405001/01/2020117HET
406001/01/202066HET
413901/01/202066WAR
414501/01/2020389WAR
414901/01/2020117HET
415725/11/2019117HET
416001/01/2020117HET
416001/01/2020117HET
416401/01/202039WAR
416601/01/2020220HET
418701/01/2020220HET
418701/01/2020220HET
418701/01/2020220HET
418701/01/2020220HET
424801/01/2020429WAR
431401/01/2019117HET
447401/01/2020444WAR
448101/01/202020WAR
448701/01/2020435WAR
449501/01/202066WAR
468501/01/2020410WAR
468801/01/2020434WAR
469101/01/2020246WAR
481310/12/2019515WAR
483201/01/2020146WAR
499701/01/2020117HET

 

Invoiced amount:

Document IDInvoiceReceived
3998398906/07/2022
3998178107/07/2022
3999451006/07/2022
4060646705/07/2022
4139657005/07/2022
4145443706/07/2022
4149655405/07/2022
4150640805/07/2022
4150704906/07/2022
4151641105/07/2022
4152441305/07/2022
4166437205/07/2022
4168672905/07/2022
4169677005/07/2022
4169654805/07/2022
4187641405/07/2022
4248645005/07/2022
4249654405/07/2022
4250654605/07/2022
4481658305/07/2022
4487661505/07/2022
4495641905/07/2022
4685644605/07/2022
4686654505/07/2022
4687654305/07/2022
4931658005/07/2022
4997661305/07/2022
4997642105/07/2022
5139648705/07/2022
5232646905/07/2022
5325645105/07/2022
5418643305/07/2022
5512641505/07/2022
5605639805/07/2022
  • Assuming that an invoice is assigned to a single region, I suggest you create a date table and a dimension table for documents & region to use in slicers, filters, measures, visuals:

    Date Table =
    VAR _CreditDates =
        SELECTCOLUMNS ( 'Credit Table', "@Date", 'Credit Table'[Validity] )
    VAR _InvoiceDates =
        SELECTCOLUMNS ( 'Invoice Table', "@Dates", 'Invoice Table'[Received] )
    VAR _ListDates =
        DISTINCT ( UNION ( _CreditDates, _InvoiceDates ) )
    VAR _MinDate =
        MINX ( _ListDates, [@Date] )
    VAR _MaxDate =
        MAXX ( _ListDates, [@Date] )
    RETURN
        ADDCOLUMNS (
            CALENDAR ( _MinDate, _MaxDate ),
            "MonthNum", MONTH ( [Date] ),
            "Month", FORMAT ( [Date], "MMMM" ),
            "Year", YEAR ( [Date] )
        )
    

    Dim Document ID =
    ADDCOLUMNS (
        DISTINCT (
            UNION (
                VALUES ( 'Credit Table'[Document ID] ),
                VALUES ( 'Invoice Table'[Document ID] )
            )
        ),
        "Region",
            LOOKUPVALUE (
                'Credit Table'[Region],
                'Credit Table'[Document ID], 'Credit Table'[Document ID]
            )
    )
    

     

    I've attached the sample PBIX file