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
flaviobdsti
Helper I
Helper I

Calculation with virtual table

Hi guys! I hope they are fine!
I need your help!

I set up a virtual table (as shown in the image below) that shows the customer code and the total sum of sales grouped by customer.

But I have difficulty working with virtual table. I'm trying to do two measurements:

a) total number of customers with sales greater than 30k

b) sum the total sales of the top 5 customers

Can you help me? Thank you very much in advance!

 

flaviobdsti_0-1674226606746.png


I used this script for creat my virtual table

SUMMARIZE (
    TABLE,
    TABLE[CODE],
    "SALES_TOTAL", SUM ( TABLE[SALES] )
)



This code works in Dax Studio, but in Power BI occorr erro, in Dax Studio it's possible see top 5...

TOPN (
    5,
    ADDCOLUMNS (
        VALUES ( TABLE[CODE] ),
        "TOTAL", CALCULATE ( SUM ( TABLE[SALES_TOTAL] ) )
    ),
    [TOTAL], DESC
)

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure whether I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your data model.

 

Jihwan_Kim_0-1674228359508.png

 

Sales measure: = 
SUM( 'Table'[Sales] )

 

Customer count over 30K: = 
COUNTROWS ( FILTER ( DISTINCT ( 'Table'[Code] ), [Sales measure:] >= 30000 ) )

 

Top 5 customers sales: =
CALCULATE (
    [Sales measure:],
    KEEPFILTERS ( TOPN ( 5, ALL ( 'Table'[Code] ), [Sales measure:], DESC ) )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Jihwan_Kim
Thank you very much, this is exactly what I need.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure whether I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your data model.

 

Jihwan_Kim_0-1674228359508.png

 

Sales measure: = 
SUM( 'Table'[Sales] )

 

Customer count over 30K: = 
COUNTROWS ( FILTER ( DISTINCT ( 'Table'[Code] ), [Sales measure:] >= 30000 ) )

 

Top 5 customers sales: =
CALCULATE (
    [Sales measure:],
    KEEPFILTERS ( TOPN ( 5, ALL ( 'Table'[Code] ), [Sales measure:], DESC ) )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Jihwan_Kim
Thank you very much, this is exactly what I need.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors