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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PowerUser123
Helper II
Helper II

Measure using USERELATIONSHIP Combined with Filter?

So my data is structured as follows: 

 

I have a traffic table that is by person and the date they visited. I have another column for the date that person first visited called OrginationDate. Finally I have an ID column which is how the traffic table is connected to the below sales table.

PowerUser123_0-1661263013830.png

 

 

Then I have a sales table that shows sales by person and date.

PowerUser123_0-1661263858795.png

 

 

The sales table is connected to my calendar table by date. I have an indirect connection connecting the traffic table's origination date to the calendar table as well.

 

From the data above a measure such as: 

 

TotalSales = SUM('Sales'[Sales])

 

produces:

PowerUser123_3-1661263425129.png

 

A measure to show sales by origination using userelationship would be:

 

Sales by Origination = CALCULATE(SUM('Sales'[Sales]),USERELATIONSHIP('Traffic'[OriginationDate],Calendar[Date]))

 

produces:

PowerUser123_4-1661263527750.png

 

I ultimately would like to show the below table:

PowerUser123_2-1661263197927.png

 

I'm using a matrix visual with the year from my calendar table as the rows. 

 

The columns in the above visual would be measures for each year (2021 and 2022). I can't figure out how to do the measure. For 2022, I would want to essentially take the TotalSales measure, but filter it for each year someone originated in. I know how to get to that value using userelationship, but I don't know how to combine the two together in one measure. 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @PowerUser123 ,

Please refer to my pbix file to see if it helps you.

Create 2 year columnsfor the 2 table.

 

year = YEAR('origination table'[date])

 

 

 

year_ = YEAR('sales Table'[date])

 

Then create 2 measures.

 

firstresult =
VAR _year =
    YEAR ( MAX ( 'origination table'[Orginationdate] ) )
RETURN
    CALCULATE (
        SUM ( 'sales Table'[sales] ),
        FILTER (
            ALL ( 'origination table' ),
            'origination table'[year] = SELECTEDVALUE ( 'origination table'[year] )
                && 'origination table'[person] = SELECTEDVALUE ( 'origination table'[person] )
        )
    )
modified =
VAR _b =
    SUMMARIZE (
        'origination table',
        'origination table'[Orginationdate],
        "aaa", [firstresult]
    )
RETURN
    IF (
        ISINSCOPE ( 'origination table'[Orginationdate] ),
        [firstresult],
        SUMX ( _b, [aaa] )
    )

 

Then put the 2 year columns into the matrix visual.

vpollymsft_0-1661480872882.png

If I have misunderstand your meaning, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-rongtiep-msft
Community Support
Community Support

Hi @PowerUser123 ,

Please refer to my pbix file to see if it helps you.

Create 2 year columnsfor the 2 table.

 

year = YEAR('origination table'[date])

 

 

 

year_ = YEAR('sales Table'[date])

 

Then create 2 measures.

 

firstresult =
VAR _year =
    YEAR ( MAX ( 'origination table'[Orginationdate] ) )
RETURN
    CALCULATE (
        SUM ( 'sales Table'[sales] ),
        FILTER (
            ALL ( 'origination table' ),
            'origination table'[year] = SELECTEDVALUE ( 'origination table'[year] )
                && 'origination table'[person] = SELECTEDVALUE ( 'origination table'[person] )
        )
    )
modified =
VAR _b =
    SUMMARIZE (
        'origination table',
        'origination table'[Orginationdate],
        "aaa", [firstresult]
    )
RETURN
    IF (
        ISINSCOPE ( 'origination table'[Orginationdate] ),
        [firstresult],
        SUMX ( _b, [aaa] )
    )

 

Then put the 2 year columns into the matrix visual.

vpollymsft_0-1661480872882.png

If I have misunderstand your meaning, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.