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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

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 2
Jeremias_Mena08
New Member

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 devuelveLo que devuelveWhat it gives back

Here's what you should return
921872040e819c7b1c66406ead702ff5.png

Anonymous
Not applicable

Hi @Syndicate_Admin

 

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

 

vnuocmsft_0-1720057976526.png

 

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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.