Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
2 years ago

Error generating a table with a variable

Good afternoon forum,

I'm having trouble generating a pivot table. The main idea is that the table is generated from the value selected in the filter. Below I share the code made so far.

Clarifications
The selectedvalue function is not registering the selection correctly, what would be the reason?
On this particular page of the report I have a measure that also uses the selected value from the filter to perform calculations, it works well.

Most popular songs by genre =
WERE SelectedGenre = SELECTEDVALUE('Musical genre'[nombre_genero])
RETURN
SELECTCOLUMNS(
TOPN(
10,
FILTER(
'AR - CAN - CAL - GEN - PAR - SE - STR',
'AR - CAN - CAL - GEN - PAR - SE - STR'[nombre_genero] = SelectedGenre
),
'AR - CAN - CAL - GEN - PAR - SE - STR'[total_streams]
),
"Song Name", 'AR - CAN - CAL - GEN - PAR - SE - STR'[nombre_cancion],
"Streams", 'AR - CAN - CAL - GEN - PAR - SE - STR'[total_streams]
)

2 Replies

  • In the original code is the word VAR used as a keyword to identify the SelectedGenre variable.
    Here is an example.
    Here's what the code currently returns.
    Lo que devuelveWhat it gives back

    Here's what you should return

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Syndicate_Admin

     

    There seems to be a typo in your code. The WERE keyword should be VAR.

     

     

    VAR SelectedGenre = SELECTEDVALUE('Musical genre'[nombre_genero])

     

     

    If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

     

    Regards,

    Nono Chen

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