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

Finding Values that do not exist last year

Is it possible to find values that do not exist last year, using the date column of the same table?

2 ACCEPTED SOLUTIONS

@Anonymous 

 

Policies Renewed this year (present in both):

Renewed Policies = 
VAR PolTY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
            YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())))
VAR PolLY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
            YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())-1))
Return
COUNTROWS(
    INTERSECT(PolLY; PolTY))

 

Policies not renewed (present last year but not this year):

Policies Not in this Year = 
VAR PolTY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())))
VAR PolLY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())-1))
Return
COUNTROWS(
    EXCEPT(PolLY; PoltY))

 

Which gets you this result:

Results.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

Anonymous
Not applicable

I did more research and found that this was able to provide the data i needed.

 

UnRenewed Policies = 
VAR PolTY = CALCULATETABLE(VALUES('PY WrittenPremium'[Policy Number]),
            FILTER('PY WrittenPremium',
                MONTH('PY WrittenPremium'[Policy Effective Date]) = MONTH(TODAY()) &&
                YEAR('PY WrittenPremium'[Policy Effective Date]) = YEAR(TODAY())           
            ))

VAR PolLY = CALCULATETABLE(VALUES('PY WrittenPremium'[Policy Number]),
            FILTER('PY WrittenPremium',
                MONTH('PY WrittenPremium'[Policy Effective Date]) = MONTH(TODAY()) &&
                YEAR('PY WrittenPremium'[Policy Effective Date]) = YEAR(TODAY())-1
            ))

Return
EXCEPT(PolLY,PolTY)

  Thank you for all your help! 

View solution in original post

19 REPLIES 19
PaulDBrown
Community Champion
Community Champion

@Anonymous 

 

The answer is yes...but what values are you trying to look for? Dates (since you mention dates column...)?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

I am trying to find if the policy exists last year based off this single table.

 

Policy Number

Policy Effective DateWritten Premium NEWNamed Insured
POLICY11/1/2019240,781COMPANY1
POLICY21/1/201965,649COMPANY2

@Anonymous 

 

Try this to identify policies present this year but not last year:

Let your table be "Data Table":

 

Policies not in Last Year = 
VAR PoliciesThisYear = CALCULATETABLE(VALUES(Data Table [Policy Number]),
                      FILTER( Data Table,
                              YEAR(Data Table[Policy Effective Date]) = YEAR(TODAY())))
VAR PoliciesLastYEAR = CALCULATETABLE(VALUES(Data Table [Policy Number]),
                      FILTER( Data Table,
                              YEAR(Data Table[Policy Effective Date]) = YEAR(TODAY())-1))

RETURN
COUNTROWS(
     EXCEPT(PoliciesThisYear, PoliciesLastYear)

 

 

And add this measure to a table with the Policy Number as a row.

 

Does it work?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

This is returning a 1 for each row.  will it be possible to check if the policy existed  the same date last year, so in the below example it will check for POLICY1 1/1/2019.

 

Edit: added more rows to match what I have. So in this scenario, I have POLICY1 that renewed for 2020.  but POLICY2 and POLICY3 did not.

 

Policy Number

Policy Effective DateWritten Premium NEWNamed Insured
Policies not in Last Year
POLICY11/1/2019240,781COMPANY11
POLICY21/1/201965,649COMPANY21
POLICY11/1/202044,048COMPANY11
POLICY31/1/201924,579COMPANY31

@Anonymous 

 

Policies Renewed this year (present in both):

Renewed Policies = 
VAR PolTY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
            YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())))
VAR PolLY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
            YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())-1))
Return
COUNTROWS(
    INTERSECT(PolLY; PolTY))

 

Policies not renewed (present last year but not this year):

Policies Not in this Year = 
VAR PolTY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())))
VAR PolLY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())-1))
Return
COUNTROWS(
    EXCEPT(PolLY; PoltY))

 

Which gets you this result:

Results.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown 

 

Thank you, i am still new to DAX.  Are you creating a new table with that code? or is it a Column? the IDE is complaining about syntax so i fear i am doing this wrong.

@Anonymous 

The CALCULATETABLE function does create a new table (with a single column, unless you add further functions), BUT... when included in a measure, you need to wrap it in an aggregator: measures can only return a single value (they can't return a list of values) Hence the COUNTROWS function.
So when you use any table function within a measure (FILTER, CALCULATETABLE, SUMMARIZE, ADDCOLUMNS etc), the table is created virtually -in memory. 

The solution I have submitted in effect is creating two tables virtually (in each of the measures). 
the first VAR creates a table (virtual) which generates a list of values present this year. The second VAR does the same but for last year.

you can then use the functions:

INTERSECT; which compares both virtual tables and ONLY returns values present in both (virtual) tables.

EXCEPT: compares the first table in the expression vs the second table included and returns a list of values which are present in the first table but not in the second. Therefore which table goes first in the expression is relevant, as you can see in the measure submitted.

Finally, the COUNTROWS function counts the values in the virtual list resulting from the INTERSECT/EXCEPT FUNCTIONS to return a single value for the measure.

I hope that's not too confusing...

 

can you post the measure which is giving you problems and the error message?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Wow thank you for this explanation, make sense.

 

I am using the measure posted with the data tables and fields changed to match my model. 

 

I may not be understanding where this code needs to be inserted.  I have tried plugging this code into a measure or column from within the table I am working with and I also tried creating a new table.

 

Also, if i have the table below how would i be able to accomplish the last column?  Essentially we need to identify policies that were renewed and visualize this.

 

Policy Number

Policy Effective DateWritten Premium NEWNamed Insured
Renewed
POLICY11/1/2019240,781COMPANY1 
POLICY21/1/201965,649COMPANY2No
POLICY11/1/202044,048COMPANY1Yes
POLICY31/1/201924,579COMPANY3No

 

@Anonymous
These are measures which you can use in a table or in the filter pane to filter a table to see the values (the examples I posted are either tables. The table with the numbers include the actuals measures; the tables where you only see the values are table visuals which are filtered in the filter pane by the measures.
Does that make sense?




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

ok, i tried creating a new measure in my table and the IDE is complaining about syntax.  Sorry for the back and forth.

 

 

image.png

@Anonymous 

Apologies since I didn't adjust my measures. just change the " ; " for " ," in the syntax (my local settings require " ; " as expression seperators).

See if that solves the issue.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Thank you, that fixed it!

 

I was able to return the policy numbers in that query, but how do I get more values from the table to return?

@Anonymous 

 

Sorry, I don't understand your last question. Can you elaborate a little?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Policies Not in this Year = 
VAR PolTY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())))
VAR PolLY = CALCULATETABLE(VALUES('DataTable'[Policy Number]);
            FILTER('DataTable';
                YEAR('DataTable'[Policy Effective Date]) = YEAR(TODAY())-1))
Return
COUNTROWS(
    EXCEPT(PolLY; PoltY))

 

Instead of returning COUNTROWS, how do I return all the values of the table so I can report on policy number and date?

@Anonymous 

To calculate the date when it from the previous year:

Last Effective Date = IF([Policies Not in this Year] >0; 
                         MAX('DataTable'[Policy Effective Date]); 
                            BLANK())

You can for example either create a table and include the measure:

Not renewed.JPG

 

or create a table and use the measure in the Filter Pane:

Not renewed FP.JPG

 

Does that help?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

ok I think I am getting closer.  thank you for all your help!

Another wrench was thrown in, we need to report on any policy that did not renew from last year a little different.  If the policy does not exist in the same month of last year, then the policy did not renew.

how would that be done?

Anonymous
Not applicable

I did more research and found that this was able to provide the data i needed.

 

UnRenewed Policies = 
VAR PolTY = CALCULATETABLE(VALUES('PY WrittenPremium'[Policy Number]),
            FILTER('PY WrittenPremium',
                MONTH('PY WrittenPremium'[Policy Effective Date]) = MONTH(TODAY()) &&
                YEAR('PY WrittenPremium'[Policy Effective Date]) = YEAR(TODAY())           
            ))

VAR PolLY = CALCULATETABLE(VALUES('PY WrittenPremium'[Policy Number]),
            FILTER('PY WrittenPremium',
                MONTH('PY WrittenPremium'[Policy Effective Date]) = MONTH(TODAY()) &&
                YEAR('PY WrittenPremium'[Policy Effective Date]) = YEAR(TODAY())-1
            ))

Return
EXCEPT(PolLY,PolTY)

  Thank you for all your help! 

@Anonymous 

Well done!!





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Thanks! Now that we have last year vs this year. How would I be able to create a trend. Month over month?

We know the table is calculated based on today. But how do I keep historicals if policies count month over month

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.