Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ADVANCE LEVEL POWER BI QUESTION SET-1 ?

Q1: Find how much amount is spent by each customer on artists ?


Write a query to return customer name, artist name and total spent ?

best_selling_artist =
SELECTCOLUMNS (
SUMMARIZE (
'invoice_line',
'Artist'[artist_id],
'artist'[name],
"total_sales", SUMX('invoice_line', invoice_line[unit_price] *
invoice_line[quantity])
),
"artist_id", [artist_id],
"artist_name", [name],
"total_sales", [total_sales]
)

● This calculation creates a table called best_selling_artist.

● It uses the SUMMARIZE function to group data from the 'invoice_line'

table by artist, calculating the total sales for each artist. It retrieves
the artist's ID and name from the 'Artist' table.
● The SELECT COLUMNS function is then used to select specific

columns from the summarized table, renaming them as "artist_id",


"artist_name", and "total_sales".
VAR BestSellingArtist =
SUMMARIZE (
'invoice_line',
customer[customer_id],customer[first_name],customer[last_name],
'best_selling_artist'[artist_name],
"amount_spent", SUMX('invoice_line', 'invoice_line'[unit_price] *
invoice_line[quantity])
)

● This defines a variable called BestSellingArtist.

● It uses the SUMMARIZE function to group data from the 'invoice_line'

table by customer and the best selling artist.


● It calculates the amount spent by each customer on purchases from
the best selling artist.
● The columns selected include customer information (customer_id,

first_name, last_name), the best selling artist's name, and the total
amount spent.

RETURN
SELECTCOLUMNS (
BestSellingArtist,
"customer_id",customer[customer_id],
"first_name",[first_name],
"last_name",[last_name],
"artist_name", 'best_selling_artist'[artist_name],
"amount_spent", [amount_spent]

)
● This is the return statement of the calculation.
● It uses the SELECT COLUMNS function to select columns from the
BestSellingArtist variable.
● The selected columns are renamed as "customer_id", "first_name",
"last_name", "artist_name", and "amount_spent".

OUTPUT:

You might also like