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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
dariaglb
Frequent Visitor

DAX mesures for compare text and dates in rows in one table with index

Hi

I have index's table where one sujbect has 3 rows with data, which need to compare with this logic:

 

if dates in columne "Date" "05-001-A" > "05-001-B"

then need to compare with date in 05-001 - 

else compare dates in 05-001-B and 05-001.

 

and second DAX mesure -

need to compare text in columne "Text" between 05-001 and 05-001-B

 

 

for result of both mesure - i need to get is 0 or 1 for color background of incorrect rows in 05-001

 

initial table:

subjectindexDateText
05-001104.06.2024Text 1
05-001-A212.05.2024 
05-001-B305.06.2024Text 2
06-001412.03.2024Text 3
06-001-A512.03.2024 
06-001-B610.03.2024Text 3

 

 

find mistakes - incorrect:

 

subjectindexDateText
05-001104.06.2024Text 1
05-001-A212.05.2024 
05-001-B305.06.2024Text 2
06-001412.03.2024Text 3
06-001-A512.03.2024 
06-001-B610.03.2024Text 3
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from @bhanu_gautam , please allow me to provide another insight:
Hi  @dariaglb ,

 

Here are the steps you can follow:

1. Create calculated column.

IF =
IF(
MOD('Table'[index],3)=0,1,0)
Group =
SUMX(
    FILTER(ALL('Table'),
    'Table'[index]>=EARLIER('Table'[index])),[IF])
Index_Group =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Group]=EARLIER('Table'[Group])),[index],,ASC)

vyangliumsft_0-1721871132365.png

2. Create measure.

Measure1 =
var _index1=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[Date])
var _index2=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=2),[Date])
var _index3=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[Date])
var _su1=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[subject])
var _su2=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=2),[subject])
var _su3=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[subject])
return
IF(
    _index2>_index3,
        IF(
        _index2>_index1,_su2,_su1),
    IF(
        _index3>_index1,_su3,_su1))
Measure2 =
var _text1=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[Text])
var _text3=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[Text])
return
IF(
_text1<>_text3&&MAX('Table'[index])=1,"red")

3. Select [Text] – Conditional formatting – Background color.

vyangliumsft_1-1721871132367.png

vyangliumsft_2-1721871225875.png

4. Result:

vyangliumsft_3-1721871235131.png

 

 

Best Regards,

Liu Yang

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

3 REPLIES 3
Anonymous
Not applicable

Thanks for the reply from @bhanu_gautam , please allow me to provide another insight:
Hi  @dariaglb ,

 

Here are the steps you can follow:

1. Create calculated column.

IF =
IF(
MOD('Table'[index],3)=0,1,0)
Group =
SUMX(
    FILTER(ALL('Table'),
    'Table'[index]>=EARLIER('Table'[index])),[IF])
Index_Group =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Group]=EARLIER('Table'[Group])),[index],,ASC)

vyangliumsft_0-1721871132365.png

2. Create measure.

Measure1 =
var _index1=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[Date])
var _index2=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=2),[Date])
var _index3=
MINX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[Date])
var _su1=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[subject])
var _su2=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=2),[subject])
var _su3=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[subject])
return
IF(
    _index2>_index3,
        IF(
        _index2>_index1,_su2,_su1),
    IF(
        _index3>_index1,_su3,_su1))
Measure2 =
var _text1=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=1),[Text])
var _text3=
MAXX(FILTER(ALL('Table'),'Table'[Group]=MAX('Table'[Group])&&'Table'[Index_Group]=3),[Text])
return
IF(
_text1<>_text3&&MAX('Table'[index])=1,"red")

3. Select [Text] – Conditional formatting – Background color.

vyangliumsft_1-1721871132367.png

vyangliumsft_2-1721871225875.png

4. Result:

vyangliumsft_3-1721871235131.png

 

 

Best Regards,

Liu Yang

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

bhanu_gautam
Super User
Super User

@dariaglb , I have tried to create two measure for comparsion on your sample data and one measure to combine the outcome of two measure I am attaching PBIX file here but in the combined measure currently in sample data I am not getting one for any row you can check and update condition as per your requirement




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi, thx for your solution,🙃
but subjects maybe several (06-001, 07-002, 05-002) and for it maybe need to use index of group of 3 rows? how do You think? i dont' know how to implement this 🤔

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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