0

I am confused with pivot tables, and it's a recurring issue! Say I have put 2 tables in my data model (classes and students):

tables classes and students

My model is this one:

enter image description here

I want to build this simple pivot table, displaying under classname, student name (no sum or number, just plain values) like so.

expected pivot table

If I do it like that, as proposed by @Cpt.Whale :

enter image description here

I get all students under each class like in a cartesian product. I just want to get the students who are associated with the class. If student fname were in class table, I simply would do a hierarchy. I want to do the equivalent of the hierarchy with the 2 tables. It might be obvious, but I cannot do it!

Update

I tried again and found a way to do it using RELATED() DAX function in a calculated column :

enter image description here

I this case, the solution proposed by @Cpt.Whale indeed works correctly :

enter image description here

Is there a better and simpler way without using a calculated column, directly in Pivot Table, with kind of an implicit RELATED funtion ?

Sorry for all screenshots being in French Excel.

5
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Dec 7, 2023 at 17:16
  • Try and move fname to the Rows (Lignes) section and place it under classname. Does that give you the view you want?
    – Cpt.Whale
    Commented Dec 7, 2023 at 17:51
  • @Cpt.Whale I did what you proposed in first trial. I realised it wasn't correct, as all students appear under each classname (see last image of my post). I just want the related ones. I thought that it's the purpose of relationships, but strangely enough I'm stuck with this simple question! I finally did it with RELATED() DAX function (see my update), but I guess there would be a better way.
    – jgran
    Commented Dec 7, 2023 at 20:10
  • I found it also works correctly if you have any column from the local table in the Values section, like count of classname or your calculated column, but never(?) when using foreign columns. Maybe buggy behavior with the internal olap connections? I'm not sure...
    – Cpt.Whale
    Commented Dec 7, 2023 at 23:33
  • @Cpt.Whale I don't think there there is a bug here, just that I don't understand the way it works and the origin of this 'cross join'.
    – jgran
    Commented Dec 8, 2023 at 15:44

1 Answer 1

0

If data is sorted this way, in Office 365 you could also achieve it using formula:

=HSTACK(MAP(classes[classname],LAMBDA(a,IF(COUNTIF(TAKE(classes[classname],1):a,a)-1,"",a))),
        XLOOKUP(Students[studentid],students[studentid],students[fname]))

Where you could replace TAKE(classes[classname],1) with the first cell ID, like A3 or if you start in the same row as the table with classes[@classname]

enter image description here

1
  • Thanks for your answer. Unfortunately, I don't have any Microsoft 365 subscription, so no access to lambda, not even hstack or map function, 🤷. Anyway a lot too advanced to my Excel level as of now !
    – jgran
    Commented Dec 11, 2023 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .