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
Anonymous
Not applicable

Issus combining USERELATIONSHIP and FILTER in a measure

Hi,

I am very new to Power BI and I can’t seem to resolve my most recent issue.  I have searched for a solution to this issue without any success.  If someone out there can help me, I would really appreciate it.

 

I have created the measure below which creates the table below:

Shipped Monthly =

CALCULATE (  

    COUNT (‘Issues'[Resolved]),  (‘Issues'[State] = "Shipped" ) ,

            USERELATIONSHIP ( ‘Issues'[Resolved], 'Date'[Date] )

 

Month

Upload Total

Shipped Total

January

1

 

February

4

 

March

8

2

April

9

 

May

16

5

June

24

6

July

 

3

August

32

 

September

48

7

October

56

6

November

57

4

December

 

 

 

Data Details:

  1. The month column is the month from the Date table.
  2. The Upload Total is derived via the active relationship between the Issues[Resolved Date] and the Date[date]
  3. The Shipped Total is derived via the inactive relationship between the Issues[Resolved Date] and the Date[date]
  4. All my data is correct

My Issues:

  1. I am not able to get a running total for the Shipped Total column even when I add a filter to my measure.  I updated my measure to look like the syntax below and instead of getting a running total the entire Shipped Total column is blanked out.  This made me think it was datatype related but I doubled checked to be sure all my dates were indeed similar date data types.  I also noticed that if I comment out my USERELATIONSHIP line the filter line is executed as expected but then uses the active relationship which returns incorrect data.  I need the filter to be executed after the USERELATIONSHIP to return the correct data.  Can someone please help me correct this measure?

 

Shipped Monthly =

CALCULATE (  

    COUNT (‘Issues'[Resolved]),  (‘Issues'[State] = "Shipped" ) ,

            USERELATIONSHIP ( ‘Issues'[Resolved], 'Date'[Date] ) ,

                     FILTER (ALL (‘Issues'), ( ‘Issues'[Resolved ]  <= MAX (‘Issues'[Resolved] ) ) )   

 

  1. I would like to replace all blank values with the previous months total value, but I don’t know how to do this.  For example, I would like the Upload Total for the month of July to be 24.  Again the Upload Total is leveraging an active relationship.  Syntax for the inactive relationship would be helpful as well if it is different from the active relationship.   This will correct the gap I am seeing in my line graph. 

 

Active Relationship

sbr_1-1605691488680.png

 

 

Inactive Relationship

sbr_2-1605691488690.png

 

 

 

 

 

2 ACCEPTED SOLUTIONS

Hi, @Anonymous 

 

You can try this:

13.png

If it doesn't work correctly,maybe it’s a behavior of ‘USERELATIONSHIP’,The filter added later still uses the original relationship.If you don't use filter, the 'calculate' function will automatically filter the corresponding data in inactive relationships(date-resolved) based on the current context.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Anonymous
Not applicable

After additional research and debugging, I was able to come up with the following measure that does exactly what I need.  Below is what I changed:

  1. Removed the "('Issues'[Resolved] <> BLANK()) line since it wasn't adding any value to my results.  
  2. Added "ALL" to my FILTER line
  3. Added VARs to enable the readability,  enable the year and month compare in my IF statement to display values in my line graph up to the current year/month.

 

VAR FirstShippedDate = CALCULATE(MINX('Issues', 'Issues'[Resolved] ) , ('Issues'[State] = "Shipped" ), ALL ('Issues' ))
VAR LastShippedDate = CALCULATE (MAXX('Issues', 'Issues'[Resolved - Copy-yyyy-mm]) ,('Issues'[State] = "Shipped" ), ALL ('Issues' ) )
Var MaxCalendarDate = MAXX('Date', 'Date'[Year-Month])

Return
IF ( MaxCalendarDate > LastShippedDate && MaxCalendarDate > TODAY(),
BLANK(),
CALCULATE( COUNT ( 'Issues'[Resolved] ),
('Issues'[State] = "Shipped" ),
USERELATIONSHIP ('Date'[Date], 'Issues'[Resolved] ) ,
FILTER ( ALL('Date' ), ('Date'[Date] <= MAX('Date'[Date]) ))
) )

 

Thanks so much for implying that there were issues with my measure and guiding me to dig deeper.  I initially thought that a FILTER statement could not follow a USERELATIONSHIP statement, but that is not the case.  

 

Thanks!!!

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

sorry for all the typing mistakes.  please overlook them.

Anonymous
Not applicable

Thank you so much for your response.  FYI:  The measure works great without the FILTER statement.  The issue I am incountering is that the FILTER statement I have added to the end of the measure is not providing me a running total in the "Shipped Total" column as expected.  Dy you have any advise about how to incoorporate this FILTER statement so that I can get the running total?  Below is the measure I am using with the filter included.  

 

Shipped Monthly = (
CALCULATE (COUNT ('Issues'[Resolved]),
      ('Issues'[State] = "Shipped" ) ,
      ('Issues'[Resolved] <> BLANK() ) ,
      USERELATIONSHIP ('Date'[Date], 'Issues'[Resolved] ) ,
      FILTER(('Date'), 'Date'[Date] <= MAX ('Date'[Date]) )

 

Running this measure creates the following data in the "Shipped Total' column".  It appears to be ingnoring the FILTER completly.  

Month

Upload Total

Shipped Total

January

1

 

February

4

 

March

8

2

April

9

 

May

16

5

June

24

6

July

 

3

August

32

 

September

48

7

October

56

6

November

70

6

December

 

 

The desired results should look as follows in the "Shipped Total' column":

Month

Upload Total

Shipped Total

January

1

 

February

4

 

March

8

2

April

9

2

May

16

7

June

24

13

July

 

16

August

32

16

September

48

23

October

56

29

November

70

35

December

 

 

 

Does anyone have any advice on how I can get the running total to appear in the 'Shipping Total" column?  

Any advice provided would be most appreciated.  I am completly out of ideas!!!

Hi, @Anonymous 

 

You can try this:

13.png

If it doesn't work correctly,maybe it’s a behavior of ‘USERELATIONSHIP’,The filter added later still uses the original relationship.If you don't use filter, the 'calculate' function will automatically filter the corresponding data in inactive relationships(date-resolved) based on the current context.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Anonymous
Not applicable

After additional research and debugging, I was able to come up with the following measure that does exactly what I need.  Below is what I changed:

  1. Removed the "('Issues'[Resolved] <> BLANK()) line since it wasn't adding any value to my results.  
  2. Added "ALL" to my FILTER line
  3. Added VARs to enable the readability,  enable the year and month compare in my IF statement to display values in my line graph up to the current year/month.

 

VAR FirstShippedDate = CALCULATE(MINX('Issues', 'Issues'[Resolved] ) , ('Issues'[State] = "Shipped" ), ALL ('Issues' ))
VAR LastShippedDate = CALCULATE (MAXX('Issues', 'Issues'[Resolved - Copy-yyyy-mm]) ,('Issues'[State] = "Shipped" ), ALL ('Issues' ) )
Var MaxCalendarDate = MAXX('Date', 'Date'[Year-Month])

Return
IF ( MaxCalendarDate > LastShippedDate && MaxCalendarDate > TODAY(),
BLANK(),
CALCULATE( COUNT ( 'Issues'[Resolved] ),
('Issues'[State] = "Shipped" ),
USERELATIONSHIP ('Date'[Date], 'Issues'[Resolved] ) ,
FILTER ( ALL('Date' ), ('Date'[Date] <= MAX('Date'[Date]) ))
) )

 

Thanks so much for implying that there were issues with my measure and guiding me to dig deeper.  I initially thought that a FILTER statement could not follow a USERELATIONSHIP statement, but that is not the case.  

 

Thanks!!!

v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

Try this:

Shipped Total =
(
    CALCULATE (
        COUNT ( 'Issues'[Resolved] ),
         ( 'Issues'[State] = "Shipped" ),
         ( 'Issues'[Resolved] <> BLANK () ),
        USERELATIONSHIP ( 'Date'[Date], 'Issues'[Resolved] )
    )
)

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Anonymous
Not applicable

I have uploaded a sample data file. I have also modified my Shipped Total measure and I am no longer getting the total shipped on every line in the table as before. Progress however small is always good.

Details:

  1. My Upload Total Measure works perfectly. The Date Table(1) and the Issues Table (many) have an active relationship setup (measure below):

Upload Total = (CALCULATE (

IF (Calculate (COUNT ('Issues'[Issue Id]) = BLANK() ) ,

(Calculate (COUNT ('Issues'[Issue Id] ) ,

FILTER(ALLSELECTED('Issues'),

('Issues'[Upload Date] <= MAX('Issues'[Upload Date]))),

DATEADD ('Issues'[Upload Date], -2, MONTH )

)) ,

(Calculate (COUNT ('Issues'[Issue Id] ),

FILTER(ALLSELECTED('Issues'),

('Issues'[Upload Date] <= MAX ('Issues'[Upload Date] )))

)))

))

  1. My Shipped Total Measure is not as successful. It does calculate the monthly shipping count as expected and it utilizes the inactive relationship setup (Date Table (1) to Issue Table (many) ) correctly. I just can't seem to figure out how to get a running total for the measure. The measure I am currently using is below and I get the same results in my table whether I include the FILTER line or not.

Shipped Total = (CALCULATE (

COUNT ('Issues'[Resolved]),

('Issues'[State] = "Shipped" ) ,

('Issues'[Resolved] <> BLANK() ) ,

USERELATIONSHIP ('Date'[Date], 'Issues'[Resolved] ) ,

FILTER (('Date'), 'Date'[Date] <= MAX ('Date'[Date]) )

My table results are below.

Month

Upload Total

Shipped Total

January

1

February

4

March

8

2

April

9

May

16

5

June

24

6

July

3

August

32

September

48

7

October

56

6

November

70

6

December

I also noticed that if I switch the FILTER statement to

"FILTER(ALLSELECTED('Issues'),'Issues'[Resolved] <= MAX ('Issues'[Resolved] ) ) "

I get no results in the Shipped Total column of my table. I even tried replacing the "ALLSELECTED" with "ALL" or removing it entirely and I still ended up with a blank Shipped Total column. So it seems that using the following filter is more correct but like I said before it will not create the running total for me.

FILTER (('Date'), 'Date'[Date] <= MAX ('Date'[Date]) )

Any advice you can provide would be most appreciated!!!

Anonymous
Not applicable

Issue IdProjectResolvedStateUpload DateCase Options
CPP11-1Project A4 Mar 2020Canceled31 Jan 2020Plan + 3DP
CPP11-2Project A10 Mar 2020Shipped10 Feb 2020Plan + 3DP
CPP11-4Project A10 Mar 2020Shipped27 Feb 2020Plan + 3DP
CPP11-3Project A26 May 2020Shipped24 Feb 2020Plan + 3DP
CPP11-7Project A26 May 2020Shipped11 Mar 2020Plan + 3DP
CPP11-8Project A26 May 2020Shipped13 Mar 2020Plan + 3DP
CPP11-6Project A26 May 2020Shipped4 Mar 2020Plan + 3DP
CPP11-17Project A27 May 2020Canceled13 May 2020Plan + 3DP
CPP11-19Project A29 May 2020Shipped13 May 2020Plan + 3DP
CPP11-26Project A5 Jun 2020Shipped12 May 2020Plan + 3DP
CPP11-9Project A10 Jun 2020Canceled13 Mar 2020Plan + 3DP
CPP11-16Project A10 Jun 2020Canceled13 May 2020Plan + 3DP
CPP11-12Project A10 Jun 2020Canceled27 Apr 2020Plan + 3DP
CPP11-23Project A10 Jun 2020Shipped22 May 2020Plan + 3DP
CPP11-22Project A10 Jun 2020Shipped15 May 2020Plan + 3DP
CPP11-28Project A15 Jun 2020Shipped21 May 2020Plan + 3DP
CPP11-29Project A17 Jun 2020Shipped3 Jun 2020Plan + 3DP
CPP11-36Project A19 Jun 2020Canceled10 Jun 2020Plan + 3DP
CPP11-33Project A19 Jun 2020Canceled6 Jun 2020Plan + 3DP
CPP11-30Project A30 Jun 2020Shipped3 Jun 2020Plan + 3DP
CPP11-32Project A9 Jul 2020Shipped6 Jun 2020Plan + 3DP
CPP11-35Project A10 Jul 2020Canceled10 Jun 2020Plan + 3DP
CPP11-57Project A23 Jul 2020Shipped17 Jun 2020Plan + 3DP
CPP11-55Project A23 Jul 2020Shipped17 Jun 2020Plan + 3DP
CPP11-111Project A2 Sep 2020Shipped11 Aug 2020Plan + 3DP
CPP11-140Project A3 Sep 2020Canceled26 Aug 2020Plan + 3DP
CPP11-135Project A3 Sep 2020Canceled18 Aug 2020Plan + 3DP
CPP11-190Project A11 Sep 2020Canceled10 Sep 2020Plan + 3DP
CPP11-144Project A17 Sep 2020Shipped26 Aug 2020Plan + 3DP
CPP11-128Project A17 Sep 2020Shipped14 Aug 2020Plan + 3DP
CPP11-136Project A17 Sep 2020Shipped19 Aug 2020Plan + 3DP
CPP11-243Project A21 Sep 2020Canceled21 Sep 2020Plan + 3DP
CPP11-253Project A22 Sep 2020Canceled21 Sep 2020Plan + 3DP
CPP11-252Project A22 Sep 2020Canceled21 Sep 2020Plan + 3DP
CPP11-142Project A24 Sep 2020Shipped26 Aug 2020Plan + 3DP
CPP11-162Project A24 Sep 2020Shipped1 Sep 2020Plan + 3DP
CPP11-143Project A24 Sep 2020Shipped26 Aug 2020Plan + 3DP
CPP11-321Project A Manufacturing Ordered15 Nov 2020Plan + 3DP
CPP11-334Project A Manufacturing Ordered16 Nov 2020Plan + 3DP
CPP11-250Project A Review - Mechanical21 Sep 2020Plan + 3DP
CPP11-337Project A Review - Segmentation16 Nov 2020Plan + 3DP
CPP11-338Project A Review - Segmentation16 Nov 2020Plan + 3DP
CPP11-323Project A Submitted15 Nov 2020Plan + 3DP
CPP11-328Project A Submitted16 Nov 2020Review Case
CPP11-329Project A Submitted16 Nov 2020Plan Only
CPP11-332Project A Submitted16 Nov 2020Plan Only
CPP11-333Project A Submitted16 Nov 2020Plan + 3DP
CPP11-335Project A Submitted16 Nov 2020Plan + 3DP
CPP11-339Project A Submitted No case options

Hi,

I have jumped in late into this post but would still like to help.  Based on the sample data that you have shared, coould you clearly show the expected result.  I am not concerned with your formulas.  Just describe the business question and show me your expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

It’s my pleasure to answer for you.

Could you mind providing some sample data and the desired result?So we can help you soon.

 

Best Regards

Janey Guo

amitchandak
Super User
Super User

@Anonymous , Try like

 

Shipped Monthly =

CALCULATE (

COUNT ('Issues'[Resolved]), ('Issues'[State] = "Shipped" ) ,

USERELATIONSHIP ( 'Issues'[Resolved], 'Date'[Date] ) ,

FILTER (ALL ('DATE'), ( 'DATE'[DATE ] <= MAX ('DATE'[DATE] ) ) ))


or

Shipped Monthly =

CALCULATE (

COUNT ('Issues'[Resolved]), ('Issues'[State] = "Shipped" ) ,

USERELATIONSHIP ( 'Issues'[Resolved], 'Date'[Date] ) ,

FILTER (ALLSELECTED ('DATE'), ( 'DATE'[DATE ] <= MAX ('DATE'[DATE] ) ) ))

Anonymous
Not applicable

Sorry, I forgot to mention that I indeed tried this Filter suggested but with no success.



In my attempt to correct the filter issue, I realized the following 2 scenarios:

1. Shipped Monthly =

CALCULATE (

COUNT (‘Issues'[Resolved]), (‘Issues'[State] = "Shipped" ) ,

USERELATIONSHIP ( ‘Issues'[Resolved], 'Date'[Date] ) ,

FILTER (ALL (‘Issues'), ( ‘Issues'[Resolved ] <= MAX (‘Issues'[Resolved] ) ) )

Month

Upload Total

Shipped Total

January

1

February

4

March

8

April

9

May

16

June

24

July

August

32

September

48

October

56

November

57

December

2. And when I use the following filter, I get the total Shipped in every total field in the table (see below)

Shipped Monthly =

CALCULATE (

COUNT (‘Issues'[Resolved]), (‘Issues'[State] = "Shipped" ) ,

USERELATIONSHIP ( ‘Issues'[Resolved], 'Date'[Date] ) ,

FILTER (ALL (‘Date), ( ‘Date [Date] <= MAX (‘Date [Date] ) ) )

Month

Upload Total

Shipped Total

January

1

33

February

4

33

March

8

33

April

9

33

May

16

33

June

24

33

July

33

August

32

33

September

48

33

October

56

33

November

57

33

December

33

I have tried several syntax combinations but with no success. I know I must be overlooking something very simple because everything I have read online tells me this measure should work. Do you have any other ideas?

Anonymous
Not applicable

The 1st scenario returns a blanks in every Shipped Total cell and the 2nd scenario returns the total number of Shipped (33) in every cell of the Shipped Total. Any help is appreciated.

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.