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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
sviswanathan
Regular Visitor

Match data values from same column within a specific time period and cross validate it with another,

Hi,

I have 3 Columns AccountNumber, TimePeriod, ProductName

Use Case: Match value in AccountNumber and ProductName within the same AccountNumber and ProductName column within TimePeriod between this year and pervious year. If both AccountNumber and ProductName in the same row matches with the same AccountNumber and ProductName in another row then the associated column should display as Legacy else New.

 

Sample Date

AccountNumTimePeriodProductNameColumn Result
123451-Nov-23HikeLegacy
123447-Mar-23CycleLegacy
145675-May-24CarLegacy
178901-Dec-21TruckLegacy
1234511-Jun-24HikeLegacy
1897015-Nov-23AutoLegacy
1789022-Apr-24TrainNew
1234520-Jul-24TrainNew

 

I have tried many times in DAX but not able to get hte right combination.

 

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @sviswanathan  Can you try below calculated column replace table name with your model table

currently i have used legne

Column Result_R =
VAR CurrentYear = YEAR(TODAY())
VAR CurrentYearStart = DATE(CurrentYear, 1, 1)
VAR PreviousYearStart = DATE(CurrentYear - 1, 1, 1)
VAR CurrentYearEnd = DATE(CurrentYear, 12, 31)
VAR PreviousYearEnd = DATE(CurrentYear - 1, 12, 31)

VAR IsCurrentOrPreviousYear =
'Legne'[TimePeriod] >= PreviousYearStart &&
'Legne'[TimePeriod] <= CurrentYearEnd

VAR IsLegacy =
CALCULATE(
COUNTROWS('Legne'),
FILTER(
'Legne',
'Legne'[AccountNum] = EARLIER('Legne'[AccountNum]) &&
'Legne'[ProductName] = EARLIER('Legne'[ProductName]) &&
'Legne'[TimePeriod] < CurrentYearStart &&
'Legne'[TimePeriod] >= PreviousYearStart
)
) > 0

RETURN
IF(
IsCurrentOrPreviousYear &&
IsLegacy,
"Legacy",
"New"
)

 

rajendraongole1_0-1724784299148.png

getting result:

rajendraongole1_1-1724784315515.png

 

 

Hope this helps





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

Proud to be a Super User!





View solution in original post

2 REPLIES 2
sviswanathan
Regular Visitor

Perfecto! Thanks worked like a charm. @rajendraongole1 

rajendraongole1
Super User
Super User

Hi @sviswanathan  Can you try below calculated column replace table name with your model table

currently i have used legne

Column Result_R =
VAR CurrentYear = YEAR(TODAY())
VAR CurrentYearStart = DATE(CurrentYear, 1, 1)
VAR PreviousYearStart = DATE(CurrentYear - 1, 1, 1)
VAR CurrentYearEnd = DATE(CurrentYear, 12, 31)
VAR PreviousYearEnd = DATE(CurrentYear - 1, 12, 31)

VAR IsCurrentOrPreviousYear =
'Legne'[TimePeriod] >= PreviousYearStart &&
'Legne'[TimePeriod] <= CurrentYearEnd

VAR IsLegacy =
CALCULATE(
COUNTROWS('Legne'),
FILTER(
'Legne',
'Legne'[AccountNum] = EARLIER('Legne'[AccountNum]) &&
'Legne'[ProductName] = EARLIER('Legne'[ProductName]) &&
'Legne'[TimePeriod] < CurrentYearStart &&
'Legne'[TimePeriod] >= PreviousYearStart
)
) > 0

RETURN
IF(
IsCurrentOrPreviousYear &&
IsLegacy,
"Legacy",
"New"
)

 

rajendraongole1_0-1724784299148.png

getting result:

rajendraongole1_1-1724784315515.png

 

 

Hope this helps





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

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors