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
AndrewPF
Helper V
Helper V

coalesce across rows, not columns

My data consists of (1) assessment ID (2) assessment name (3) question number (4) target score and (5) actual score. 

 

I have some reassessments on which only specific questions have been answered - i.e. those which were under target in the previous assessment. 

 

How can I create a data set which shows new questions only where they have been replaced by existing previous ones? 

 

Example: 

 

Actual data: 

 

Assessment IDNameQuestion no.Target scoreActual scoreNotes
123Initial133on target - no reassessment required
123Initial243not on target
123Initial355on target - no reassessment required
123Initial421not on target
123Initial533on target - no reassessment required
245Reassessment244 
245Reassessment422 

 

Required data: 

 

Assessment IDNameQuestion no.Target scoreActual scoreNotes
123Initial133 
245Reassessment244reassessment - superceded previous answer
123Initial355 
245Reassessment422reassessment - superceded previous answer
123Initial533 

 

This problem is perfectly clear in my own head, I just hope I have effectively conveyed it here! 

1 ACCEPTED SOLUTION

@AndrewPF it should work. Edit GroupedRows step to something like this:

GroupedRows = Table.Group(ReplaceNotes, {"business ID" ,"Question no."}, {{"Detail", each _, type table}, {"Result", each Table.LastN(_, 1) }}),

 

If it won't work just send new sample data and I'll try to help you.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
AndrewPF
Helper V
Helper V

Hi, 

thanks for the response. 

I probably should have clarified in my original post, but my data is more complicated than in the example.  Aside from lots of other columns (which I think I can deal with), I have up a business ID, for which we can have any number of assessments (we're currently at a maximum of 6 for any one business ID). 

So I wonder - if I group by business ID and question number, would that still work? 

@AndrewPF it should work. Edit GroupedRows step to something like this:

GroupedRows = Table.Group(ReplaceNotes, {"business ID" ,"Question no."}, {{"Detail", each _, type table}, {"Result", each Table.LastN(_, 1) }}),

 

If it won't work just send new sample data and I'll try to help you.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

dufoq3
Super User
Super User

Hi @AndrewPF,

Result:

dufoq3_0-1706907870204.png

 

I expect that Reassesment (for same question) is everytime below the Initial in your table (let me know if it isn't)

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJR8szLLMlMzAGyDIHYGIrz8xRKEovSU0sUdBXy8hWKUhOLi1OLi3NT80qAnMLSzKLUFKVYHUxDjIDYBGpIXn6JAtwgrKpBPFMoJttKE6i1hkRZaUqOL41MQNqCkOSRvArCCriVwZxnBFEWCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Assessment ID" = _t, Name = _t, #"Question no." = _t, #"Target score" = _t, #"Actual score" = _t, Notes = _t]),
    ReplaceNotes = Table.ReplaceValue( Source,
      each [Name],
      null,
      (x,y,z)=> if y = "Reassessment" then "reassessment - superceded previous answer" else null,
      {"Notes"} ),
    GroupedRows = Table.Group(ReplaceNotes, {"Question no."}, {{"Detail", each _, type table}, {"Result", each Table.LastN(_, 1) }}),
    CombinedResult = Table.Combine(GroupedRows[Result])
in
    CombinedResult

 

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

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.

Top Solution Authors
Top Kudoed Authors