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

Issue with Calculated table with User's Selection

I have an excel table that looks like this:

Financial YearVAT NumberSectorNet SalesEBITDAInventories
20191001100009000800
20192002120009500900
2020100115000100001000
2020200216000100001000
202110011700013000450
2021200218000140001200
202210011900015000800
202220022000016000800
2023100121000170001200
2023200222000180001200

 

***I have a lot more columns related to the companies' balance sheet items, however I am simplifying it in this example.

 

I imported the data to PowerBI and inserted a matrix which shows the following: Financial Year, Sum of Net Sales, Sum of EBITDA, Sum of Inventories, etc.

 

I added 2 slicers: one that filters the years that appear in my matrix ('Sheet1'[Financial Year]), and one that filter the sector ('Sheet1'[Sector]).

 

I created a calculated table, which contains one column with the VATs that appear in a Common Sample. This Common Sample refers to VATs who appear both in 2022 AND 2023, and have non-zero and non-blank Net Sales in both of those years. If a VAT does not meet this criteria, its value is blank in the calculated table. This table is connected to the original table (Sheet1) via a One-to-many relationship that links 'Net Sales CS 2022-2023'[VALID NET SALESVAT] to 'Sheet1'[VAT Number]. I input this calculated table in a slicer, selected all values apart from the blank ones, and this correctly filters my matrix and shows the Sum of Net Sales, EBITDA, etc, for the filtered common sample.

 

The type of this table is the following:

Net Sales CS 2022-2023 =
VAR VATs2022 =
    FILTER(
        ALL('Sheet1'),
        'Sheet1'[Financial Year] = 2022 &&
        NOT(ISBLANK('Sheet1'[Net Sales])) &&
        'Sheet1'[Net Sales] <> 0
    )

VAR VATs2023 =
    FILTER(
        ALL('Sheet1'),
        'Sheet1'[Financial Year] = 2023 &&
        NOT(ISBLANK('Sheet1'[Net Sales])) &&
        'Sheet1'[Net Sales] <> 0
    )

RETURN
DISTINCT(
    INTERSECT(
        SELECTCOLUMNS(VATs2022, "VALID NET SALES VAT", 'Sheet1'[VAT Number]),
        SELECTCOLUMNS(VATs2023, "VALID NET SALES VAT", 'Sheet1'[VAT Number])
    )
)
 
I need help with the following query: Instead of creating a calculated table for the common sample of 2022 and 2023, I would like a calculated table with a dynamic selection of years of Common Sample, based on the users' selection. For example, a user might select the Net Sales Common Sample between 2020, 2021, and 2022. This calculated table (or column, or measure) will be added in a slicer, so that I can filter my matrix and showcase the Sum of Net Sales, EBITDA, Inventories, etc, ONLY FOR the Common Sample.
 
IMPORTANT: I don't want to create separate measures for each and every column (which means balance sheet item), as there are too many of them in my data.
 
I created a disconnected table that allows the user to select the years for which he/she wants to compute the common sample. I believe that this should be somehow to the calculated table, but not to the original table. 
 
YearSelection = DISTINCT('Sheet1'[Financial Year])
 
However, I didn't have any luck with different tries of creating a calculated table, measure, or column based on my query, SO I WOULD REALLY APPRECIATE YOUR HELP 🙂.
 
EXTRA QUERY: The user might want to select a different column than the Net Sales one to find the Common Sample of the VATs for selected years.
5 REPLIES 5
v-kathullac
Community Support
Community Support

Hi @atziovara,

 

Thanks @johnt75  for Addressing the issue.

 

we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Regards,
Chaithanya.

v-kathullac
Community Support
Community Support

Hi @atziovara,

 

Thanks @johnt75  for Addressing the issue.

 

we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Regards,
Chaithanya.

Hi @atziovara,

 

Thanks @johnt75  for Addressing the issue.

 

we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Regards,
Chaithanya.

johnt75
Super User
Super User

You can get the functionality you want by using a calculation group.

First, create a table of all the financial years for use in the slicer,

Years = DISTINCT( Sheet1[Financial Year] )

and add this column to the slicer.

Create measures which sum the columns you are interested in, e.g.

Net Sales Measure = SUM( Sheet1[Net Sales] )

Next create a calculation group and a calculation item like

By Net Sales = 
VAR SelectedYears = VALUES( 'Years'[Financial Year] )
VAR NumSelectedYears = COUNTROWS( SelectedYears )
VAR SummaryTable = ADDCOLUMNS(
    CALCULATETABLE(
        SUMMARIZE( Sheet1, Sheet1[Financial Year], Sheet1[VAT Number] ),
        TREATAS( SelectedYears, Sheet1[Financial Year] ),
        REMOVEFILTERS()
    ),
    "@value", [Net Sales Measure]
)
VAR FilteredTable = GROUPBY(
    FILTER(
        SummaryTable,
        [@value] <> 0
    ),
    Sheet1[VAT Number],
    "@num", SUMX( CURRENTGROUP(), 1)
)
VAR ValidNums = SELECTCOLUMNS(
    FILTER(
        FilteredTable,
        [@num] = NumSelectedYears
    ),
    Sheet1[VAT Number]
)
VAR Result = CALCULATE(
    SELECTEDMEASURE(),
    KEEPFILTERS( ValidNums )
)
RETURN Result

 This code calculates the number of years chosen in the slicer, works out the net sales for each VAT number in each of those years, filters out those years where the net sales is 0 or blank and then counts the number of years for each VAT number, retaining those where the number of valid years matches the number of years selected in the slicer.

If you want to allow the user to choose a measure different from net sales for doing the comparison, create another calculation item and replace the [Net Sales Measure] with the appropriate measure.

lbendlin
Super User
Super User

You cannot create calculated columns/tables from users interacting with the filter context. This only works the other way round.

 

Calculated columns/tables are calculated once, after the semantic model refresh, and do not interact.

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.