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
ckausihan_12
Helper I
Helper I

Compare Rows

Hi, I have a table (Table) which contains student data, with grades they achievd in each academic term. I have created a matrix (Matrix) which uses the data from Table and measures which identifies progress made from baseline to selected term.  I need to find a way to count the number of students who have made positive progress from baseline to select term.

 

So person1 has made progress from baseline to aut by +1, which means person1 has made positive progress and therefore would count towards the number of students who made progress from baseline to aut. However, from baseline to spr person1 made -1 progress, meaning person1 wont count towards the total for baseline to spr. I will have three totals: base to aut, base to spr and base to sum.

 

Table:

IDNameTermData_Drop_OrderBaselineAutSprSum
1234person1Sum40005
1234person1Spr30030
1234person1Aut20500
1235person1Base14000

 

Matrix:

NameBaselineAutSprSumProgBaseAutProgBaseSprProgBaseSum
person145351-11
1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @ckausihan_12 ,

 

We can use the following steps to meet your requirement.

 

1. Create three measures to calculate the difference.

 

ProgBaseAut 2 = CALCULATE(SUM('Table (2)'[Aut]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

ProgBaseSpr 2 = CALCULATE(SUM('Table (2)'[Spr]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

ProgBaseSum 2 = CALCULATE(SUM('Table (2)'[Sum]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

 

Com 1.jpg

 

2. Then we can create three measures to determine if the first three measures are greater than 0.

 

BAut 2 = IF([ProgBaseAut 2]>0,1,0)

BSpr 2 = IF([ProgBaseSpr 2]>0,1,0)

BSum 2 = IF([ProgBaseSum 2]>0,1,0)

 

Com 2.jpg

 

3. At last we can create a measure to calculate the count of person who meet the conditions.

 

count Person 2 = CALCULATE(DISTINCTCOUNT('Table (2)'[Name]),FILTER('Table (2)',[BAut 2]=1 && [BSpr 2]=1 && [BSum 2]=1))

 

The result like this,

 

Com 3.jpg

 

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

9 REPLIES 9
v-zhenbw-msft
Community Support
Community Support

Hi @ckausihan_12 ,

 

We can use the following steps to meet your requirement.

 

1. Create three measures to calculate the difference.

 

ProgBaseAut 2 = CALCULATE(SUM('Table (2)'[Aut]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

ProgBaseSpr 2 = CALCULATE(SUM('Table (2)'[Spr]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

ProgBaseSum 2 = CALCULATE(SUM('Table (2)'[Sum]),ALLEXCEPT('Table (2)','Table (2)'[Name])) - CALCULATE(SUM('Table (2)'[Baseline]),ALLEXCEPT('Table (2)','Table (2)'[Name]))

 

Com 1.jpg

 

2. Then we can create three measures to determine if the first three measures are greater than 0.

 

BAut 2 = IF([ProgBaseAut 2]>0,1,0)

BSpr 2 = IF([ProgBaseSpr 2]>0,1,0)

BSum 2 = IF([ProgBaseSum 2]>0,1,0)

 

Com 2.jpg

 

3. At last we can create a measure to calculate the count of person who meet the conditions.

 

count Person 2 = CALCULATE(DISTINCTCOUNT('Table (2)'[Name]),FILTER('Table (2)',[BAut 2]=1 && [BSpr 2]=1 && [BSum 2]=1))

 

The result like this,

 

Com 3.jpg

 

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

v-zhenbw-msft
Community Support
Community Support

Hi @ckausihan_12 ,

 

We can use the following steps to meet your requirement.

 

1. Replace [BAut], [BSpr] and [BSum] with the following three measures.

 

BAut = [ProgBaseAut]>0

BSpr = [ProgBaseSpr]>0

BSum = [ProgBaseSum]>0

 

2. Then we can create a measure to calculate the count of person who satisfies condition.

 

count Person = CALCULATE(DISTINCTCOUNT('Table'[Name]),FILTER('Table',[BAut] && [BSpr] && [BSum]))

 

The result like this,

 

Com 1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Hi @v-zhenbw-msft ,

 

Unfortuently this soltiuon won't work for me, since each person has an indivdual entry for every term. My dataset layout is as follows:

Capture.JPG

 

ckausihan_12
Helper I
Helper I

Hi @v-zhenbw-msft ,

I made some changes to clarify any confusion.

 

I have added an extra person into my example. Please see the matrix below.

Capture.JPG

 

I added three measures to calculate how much progress was made from baseline to the terms. I need these, as they will help me determine who made positive progress, stayed the same or made negative progress (I am only interested in positve progress).

ProgBaseAut = SUM('Table'[Aut]) - SUM('Table'[Baseline])
ProgBaseSpr = SUM('Table'[Spr]) - SUM('Table'[Baseline])
ProgBaseSum = SUM('Table'[Sum]) - SUM('Table'[Baseline])
 
I added three additional measures to help identify the people who made positive progress.
BAut = IF([ProgBaseAut]>0,1)
BSpr = IF([ProgBaseSpr]>0,1)
BSum = IF([ProgBaseSum]>0,1)
 
I essentially just need a count of the people who have made positive progress, so count of BAut, BSpr and Bsum when equals 1.
Please see the example table below I with my desited results:
TermNo. Positive Progress
Aut1
Spr1
Sum2
 
 
 

 

 

 

v-zhenbw-msft
Community Support
Community Support

Hello @ckausihan_12 ,

We have some confused ones.

In the matrix table, the baseline of person1 is 4, Aut is 5, Spr is 3. But in table person4 the baseline is 4, Aut of person3 is 5. And we can't imagine what your resulting wish is.

So we guess a solution and you can refer.

1. Create three measures to calculate the [ProgBaseAut], [ProgBaseSpr], [ProgBaseSum].

ProgBaseAut = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Aut]>'Table'[Baseline]))

ProgBaseSpr = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Spr]>'Table'[Baseline]))

ProgBaseSum = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Sum]>'Table'[Baseline]))

C 1.jpg

2. Then we can create a new table using Enter Date, and create a measure to summarize the three measures.

C 2.jpg

Total = 
SUMX(
    VALUES('Table (2)'[Row]),
SWITCH(
    'Table (2)'[Row],
    "ProgBaseAut",[ProgBaseAut],
    "ProgBaseSpr",[ProgBaseSpr],
"ProgBaseSum",[ProgBaseSum]))

C 3.jpg

If you do not meet your requirement, could you show the expected exact result based on the table you shared?

BTW, pbix as attached.

Best regards

Community Support Team _ zhenbw

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

v-zhenbw-msft
Community Support
Community Support

Hi @ckausihan_12 ,

 

We have some confused.

In your matrix table, the person1’s base line is 4, Aut is 5, Spr is 3. But in table person4’s base line is 4, person3’s Aut is 5. And we don’t imagine what is you desire result.

So we guess a solution and you can refer.

 

1. Create three measures to calculate the [ProgBaseAut], [ProgBaseSpr], [ProgBaseSum].

 

ProgBaseAut = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Aut]>'Table'[Baseline]))

ProgBaseSpr = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Spr]>'Table'[Baseline]))

ProgBaseSum = CALCULATE(COUNT('Table'[Name]),FILTER('Table','Table'[Sum]>'Table'[Baseline]))

 

C 1.jpg

 

2. Then we can create a new table using Enter Date, and create a measure to summarize the three measures.

 

C 2.jpg

 

Total = 
SUMX(
    VALUES('Table (2)'[Row]),
SWITCH(
    'Table (2)'[Row],
    "ProgBaseAut",[ProgBaseAut],
    "ProgBaseSpr",[ProgBaseSpr],
"ProgBaseSum",[ProgBaseSum]))

 

C 3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Hi @v-zhenbw-msft ,

 

I do apolgise for the confusion! I just spotted the error I made. The table should just contain data for person1. So it shows one persons grades for baseline, aut, spr and sum. 

Greg_Deckler
Super User
Super User

@ckausihan_12 Sorry, not following this, why exactly has Person 1 made progress from baseline to aut by +1?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , in baseline person1 scored 4 and and in aut  person1 scored 5, meaing they made a progress of +1. I have cleared up my example tables a little.

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.