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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jocky
Frequent Visitor

Check if all values in a row are the same

Hi there,

 

I am presuming this is simple, but I can't seem to find the right way to do it.

 

I have a dataset that looks like the following.

 

NameJanFebMarAprMayJunJulAugSepOctNovDec
BobAAAAAAAAAABB
JohnGGGGGGGGGGGG
SallyDDDDDDCCCCCC
SarahAAAAAAAAAAAA
CraigCBBBBBBBBBBB

 

What I want to determine is if the individual has the same letter against their name throughout all months.  This either be by a simple yes/no (or true/false) or by how many times the value is different.

 

NameJanFebMarAprMayJunJulAugSepOctNovDecAre all values the same?How many different values?
BobAAAAAAAAAABBNo2
JohnGGGGGGGGGGGGYes1
SallyDDDDDDCCCCCCNo2
SarahAAAAAAAAAAAAYes1
CraigCBBBBBBBBBBBNo2

 

 

Any idea what i would use to achieve this?

 

Thanks

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use these formulas

= [Lst=List.RemoveFirstN(Record.ToList(_),1),
r=if List.IsEmpty(List.RemoveItems(Lst,{List.First(Lst)}))then "Yes" else "No"][r]

= List.Count(List.Distinct(List.RemoveLastN(List.RemoveFirstN(Record.ToList(_),1),1)))

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPUtJRciQSO4FxrE60kld+Rh6Q404SBmkMTszJqQTyXHBgZ6wYorMoMYMEx0IwSKdzUWJmOtQsJ6JxbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Jan = _t, Feb = _t, Mar = _t, Apr = _t, May = _t, Jun = _t, Jul = _t, Aug = _t, Sep = _t, Oct = _t, Nov = _t, Dec = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Are all values the same?", each [Lst=List.RemoveFirstN(Record.ToList(_),1),
r=if List.IsEmpty(List.RemoveItems(Lst,{List.First(Lst)}))then "Yes" else "No"][r]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "How many different values?", each List.Count(List.Distinct(List.RemoveLastN(List.RemoveFirstN(Record.ToList(_),1),1))))
in
    #"Added Custom1"

 

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Use these formulas

= [Lst=List.RemoveFirstN(Record.ToList(_),1),
r=if List.IsEmpty(List.RemoveItems(Lst,{List.First(Lst)}))then "Yes" else "No"][r]

= List.Count(List.Distinct(List.RemoveLastN(List.RemoveFirstN(Record.ToList(_),1),1)))

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPUtJRciQSO4FxrE60kld+Rh6Q404SBmkMTszJqQTyXHBgZ6wYorMoMYMEx0IwSKdzUWJmOtQsJ6JxbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Jan = _t, Feb = _t, Mar = _t, Apr = _t, May = _t, Jun = _t, Jul = _t, Aug = _t, Sep = _t, Oct = _t, Nov = _t, Dec = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Are all values the same?", each [Lst=List.RemoveFirstN(Record.ToList(_),1),
r=if List.IsEmpty(List.RemoveItems(Lst,{List.First(Lst)}))then "Yes" else "No"][r]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "How many different values?", each List.Count(List.Distinct(List.RemoveLastN(List.RemoveFirstN(Record.ToList(_),1),1))))
in
    #"Added Custom1"

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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