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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
hari_krishnan
Helper I
Helper I

Creating new table in Direct query mode from existing one

Hi,

 

I have a Date range filter within my report which pulls data from the Reg_Date column from below table:

 

IDReg_DateGenderAge
12020-10-03 12:12:12M20

2

2020-11-03 12:12:12M20

3

2020-12-03 12:12:12F20

 

I also have a custom visual developed which needs data in the format below:

 

Table: stage_info_table

IDStageTotal Count
1A2

2

B3

(Note: In real case I have 8 stages which gets total count based on different columns)

 

The total count is calculated by: 

    For Stage A: Count(*) from Table_Name Where Gender = 'M'

    For Stage B: Count(*) from Table_Name Where Age = '20'

 

What I did to generate this new table: Used SQL query to create this table. And the visual is working Perfectly based on the data.

 

The issue I am stuck with is:

1. The Data range filter will not work since no relation between the main table and created table.

2. A custom visual does not support more than 30K rows, so I cannot pass my main table to the custom visual.

 

Is there any way to create this new table in the Power BI itself?

Or Any other approach to solve this issue?

 

My thoughts: Only way to achieve this is with an API? Because The total count calculation to create new table is like a UNION of multiple queries which I think is very complex to achieve in BI.

 

What I need to achieve?

Data range slider changed --> Recalculates the Total count based on Reg_Date --> Pass new data to the custom visual

 

Thanks in advance.

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi  @hari_krishnan ,

 

Have you tried instead of creating a new table, making a measure using a switch function and a table with the stages something similar to this:

 

Measure =
SWITCH (
    SELECTEDVALUE ( TableStage[Stage] );
    "A"; CALCULATE ( COUNT ( Table[Name] ); Table[Gender] = 'M' );
    "B"; CALCULATE ( COUNT ( Table[Name] ); Table[Age] = 20 );
    ...
)

 

Can work as you need, because the measure are based on context and if they are calculated based on the initial table they will be filtered out by the dates.

 

Be aware that the Stage only needs to have  A, B, C and so on without any relationship with the other table.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

5 REPLIES 5
MFelix
Super User
Super User

Hi  @hari_krishnan ,

 

Have you tried instead of creating a new table, making a measure using a switch function and a table with the stages something similar to this:

 

Measure =
SWITCH (
    SELECTEDVALUE ( TableStage[Stage] );
    "A"; CALCULATE ( COUNT ( Table[Name] ); Table[Gender] = 'M' );
    "B"; CALCULATE ( COUNT ( Table[Name] ); Table[Age] = 20 );
    ...
)

 

Can work as you need, because the measure are based on context and if they are calculated based on the initial table they will be filtered out by the dates.

 

Be aware that the Stage only needs to have  A, B, C and so on without any relationship with the other table.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix Thanks a lot. This is working 😀

 

One more question, Does passing a measure works the same way as that of a column to the Custom Visual?

Hi  @hari_krishnan ,

 

Not really sure if I understand what you mean by Custom Visual? 

 

In any visualization you can add in the values columns or measures the difference is that columns are part of your model and measures are calculated on request so when you use the measure it calculate.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix ,

 

By Custom Visual, I mean custom created visuals using the "PbiViz" library. A package provided my Microsoft to create custom charts.

Hi  @hari_krishnan ,

 

On visualizations as I refer you can use columns or measures so no problem in using them on custom visualizations, be aware that the only thing regarding measures and visualizations is that they can only be used on the values and on filters not for example on axis or legends.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.