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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Harom
New Member

Calculation based on 2 or more variables (slicer/parameter?)

Hi,

I'm new to Power BI, but not with data. I've been searching the web and this forum for the following, but without success sofar:

I'm looking for a way to get a calculation Sales Period Currency based on two variables:

  1. Currency selection (EUR/USD): I have two columns in my data set Sales Value EUR and Sales Value USD
  2. Period selection: I have several columns with Period Indicators (YTD, L12M,Etc for current year and last year). This field shows a 1 when the date for this row falls under the period condition and 0 (or maybe NULL) when this is not the case

The idea is to

 - first create a field Sales Value Currency, based on a (parameter/slicer) selection 

 - Create a field called Period Selection, based on a (parameter/slicer) selection

 - And finally create a Sales Value CUR Period = SUM(Sales Value Currency * Period Selection)

 

Combining this would make the calculation very flexibel, with a minimum of steps. Next I would like to re-use the same paramter/slicer for the same logic for Quanty and Margin calculations

Other ideas, or existing solutions are more than welcome 🙂

8 REPLIES 8
Harom
New Member

@bhanu_gautam 
Thank you for your quick reply!

When I go to Modeling > New Parameter , I get two options: Numeric Range and Fields. In both cases I'm not able to create my own two options.

@Harom Hey,
you can create your all measure then create a field parameter for the same as below image.

 

HarishKM_0-1744804814738.png


expected output as below.

 

HarishKM_2-1744804989219.png

 

 

 

Thanks
Harish M
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query

 

@Harom Hey,
try below things

1st table

CurrencySelection =
DATATABLE("Currency", STRING, {
{"USD"},
{"EUR"},
{"GBP"}
})

 

2nd table 

PeriodSelection =
DATATABLE("Period", STRING, {
{"MTD"},
{"YTD"},
{"QTD"},
{"Full Year"},
{"PY MTD"},
{"PY YTD"}
})

once you have above 2 disconnected (Newly created table) then you have create below measure

SelectedSales =
VAR SelectedCurrency = SELECTEDVALUE(CurrencySelection[Currency])
VAR SelectedPeriod = SELECTEDVALUE(PeriodSelection[Period])

-- Step 1: Apply currency conversion logic (example rate logic)
VAR SalesInCurrency =
SWITCH(
SelectedCurrency,
"USD", [Sales_USD],
"EUR", [Sales_EUR],
"GBP", [Sales_GBP],
[Sales_USD] -- default
)

-- Step 2: we have to write a period logic now
RETURN
SWITCH(
SelectedPeriod,
"MTD", CALCULATE(SalesInCurrency, DATESMTD(DateTable[Date])),
"YTD", CALCULATE(SalesInCurrency, DATESYTD(DateTable[Date])),
"QTD", CALCULATE(SalesInCurrency, DATESQTD(DateTable[Date])),
"Full Year", CALCULATE(SalesInCurrency, YEAR(DateTable[Date]) = YEAR(TODAY())),
"PY MTD", CALCULATE(SalesInCurrency, DATESMTD(SAMEPERIODLASTYEAR(DateTable[Date]))),
"PY YTD", CALCULATE(SalesInCurrency, DATESYTD(SAMEPERIODLASTYEAR(DateTable[Date]))),
SalesInCurrency -- default 
)

above solution is fully scaleble for future.

 

Thanks
Harish M
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query

@HarishKM 
I've got the Table and selected value part working. When I want to apply this in for example the VAR SalesinCurrency the way you described (I've added a New Column with the calculation), there is no result in the column.

-- Step 1: Apply currency conversion logic (example rate logic)
VAR SalesInCurrency =
SWITCH(
SelectedCurrency,
"USD", [Sales_USD],
"EUR", [Sales_EUR],
"GBP", [Sales_GBP],
[Sales_USD] -- default
)

My logic:

Sales Value Currency =
SWITCH('Par Currency'[Currency Selected],
"EUR", Query2[Amount Value],
"USD", Query2[Amount Value USD])

@HarishKM That could be an option, but we want to combine currencies and periods and with preferably one parameter/slicer for each variable, to keep it maintainable.
3 currencies x 6 different periods for at least 4/5 measures

@Harom , You can do that like

Create a Currency Selection Table:

Go to the "Home" tab and select "Enter Data".
Create a table with a single column named "Currency" and add the values "EUR" and "USD".
Name this table "CurrencySelection".
Create a Period Selection Table:

Similarly, create another table for period selection with the desired periods (e.g., YTD, L12M, etc.).
Name this table "PeriodSelection".
Create Relationships:

Ensure that these tables are not related to your main data table. They will be used solely for slicers.
Create Measures for Currency and Period Selection:

   Selected Currency =
   SELECTEDVALUE(CurrencySelection[Currency])
 
and create similar for other and use them in field parameter



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam the good news, the solution with the tables works and I managed to get all columns and measures working without errors showing, the bad news is that the new created columns stay empty. When I put the slicer in the report and a  table with the calculation, it works:

Harom_5-1744806390384.png

 


Some other screenshots:

Harom_0-1744806145085.png

Harom_1-1744806189909.png

Harom_2-1744806235873.png

Harom_3-1744806288871.png

 

 

 

bhanu_gautam
Super User
Super User

@Harom Go to the Modeling tab and select "New Parameter".
Name it "Currency Selection" and add the values "EUR" and "USD".
This will create a slicer that allows you to select between EUR and USD.

Similarly, create another parameter for period selection with the desired periods (e.g., YTD, L12M, etc.).

 

Create a Calculated Column for Sales Value Currency:

DAX
Sales Value Currency =
SWITCH(
[Currency Selection],
"EUR", [Sales Value EUR],
"USD", [Sales Value USD]
)

 

DAX
Period Selection =
SWITCH(
[Period Selection],
"YTD", [YTD Indicator],
"L12M", [L12M Indicator],
-- Add other periods as needed
)

 

Create the Final Measure for Sales Value CUR Period

DAX
Sales Value CUR Period =
SUMX(
YourTable,
[Sales Value Currency] * [Period Selection]
)

 

Reuse the Parameters for Quantity and Margin Calculations:

DAX
Quantity Value Currency =
SWITCH(
[Currency Selection],
"EUR", [Quantity Value EUR],
"USD", [Quantity Value USD]
)

Quantity Value CUR Period =
SUMX(
YourTable,
[Quantity Value Currency] * [Period Selection]
)

 

 

DAX
Margin Value Currency =
SWITCH(
[Currency Selection],
"EUR", [Margin Value EUR],
"USD", [Margin Value USD]
)

Margin Value CUR Period =
SUMX(
YourTable,
[Margin Value Currency] * [Period Selection]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

"); $(".slidesjs-pagination" ).prependTo(".pagination_sec"); $(".slidesjs-pagination" ).append("
"); $(".slidesjs-play.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-stop.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-pagination" ).append(""); $(".slidesjs-pagination" ).append(""); } catch(e){ } /* End: This code is added by iTalent as part of iTrack COMPL-455 */ $(".slidesjs-previous.slidesjs-navigation").attr('tabindex', '0'); $(".slidesjs-next.slidesjs-navigation").attr('tabindex', '0'); /* start: This code is added by iTalent as part of iTrack 1859082 */ $('.slidesjs-play.slidesjs-navigation').attr('id','playtitle'); $('.slidesjs-stop.slidesjs-navigation').attr('id','stoptitle'); $('.slidesjs-play.slidesjs-navigation').attr('role','tab'); $('.slidesjs-stop.slidesjs-navigation').attr('role','tab'); $('.slidesjs-play.slidesjs-navigation').attr('aria-describedby','tip1'); $('.slidesjs-stop.slidesjs-navigation').attr('aria-describedby','tip2'); /* End: This code is added by iTalent as part of iTrack 1859082 */ }); $(document).ready(function() { if($("#slides .item").length < 2 ) { /* Fixing Single Slide click issue (commented following code)*/ // $(".item").css("left","0px"); $(".item.slidesjs-slide").attr('style', 'left:0px !important'); $(".slidesjs-stop.slidesjs-navigation").trigger('click'); $(".slidesjs-previous").css("display", "none"); $(".slidesjs-next").css("display", "none"); } var items_length = $(".item.slidesjs-slide").length; $(".slidesjs-pagination-item > button").attr("aria-setsize",items_length); $(".slidesjs-next, .slidesjs-pagination-item button").attr("tabindex","-1"); $(".slidesjs-pagination-item button").attr("role", "tab"); $(".slidesjs-previous").attr("tabindex","-1"); $(".slidesjs-next").attr("aria-hidden","true"); $(".slidesjs-previous").attr("aria-hidden","true"); $(".slidesjs-next").attr("aria-label","Next"); $(".slidesjs-previous").attr("aria-label","Previous"); //$(".slidesjs-stop.slidesjs-navigation").attr("role","button"); //$(".slidesjs-play.slidesjs-navigation").attr("role","button"); $(".slidesjs-pagination").attr("role","tablist").attr("aria-busy","true"); $("li.slidesjs-pagination-item").attr("role","list"); $(".item.slidesjs-slide").attr("tabindex","-1"); $(".item.slidesjs-slide").attr("aria-label","item"); /*$(".slidesjs-stop.slidesjs-navigation").on('click', function() { var itemNumber = parseInt($('.slidesjs-pagination-item > a.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); });*/ $(".slidesjs-stop.slidesjs-navigation, .slidesjs-pagination-item > button").on('click keydown', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); var itemNumber = parseInt($('.slidesjs-pagination-item > button.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); }); $(".slidesjs-play.slidesjs-navigation").on('click', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); }); $(".slidesjs-pagination-item button").keyup(function(e){ var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); $(".slidesjs-stop.slidesjs-navigation").trigger('click').blur(); $("button.active").focus(); } }); $(".slidesjs-play").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-stop").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-play")) { $(".slidesjs-stop").focus(); } } }); $(".slidesjs-stop").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-play").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-stop")) { $(".slidesjs-play").focus(); } } }); $(".slidesjs-pagination-item").keydown(function(e){ switch (e.which){ case 37: //left arrow key $(".slidesjs-previous.slidesjs-navigation").trigger('click'); e.preventDefault(); break; case 39: //right arrow key $(".slidesjs-next.slidesjs-navigation").trigger('click'); e.preventDefault(); break; default: return; } $(".slidesjs-pagination-item button.active").focus(); }); }); // Start This code is added by iTalent as part of iTrack 1859082 $(document).ready(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); $("#tip2").attr("aria-hidden","true").addClass("hidden"); $(".slidesjs-stop.slidesjs-navigation, .slidesjs-play.slidesjs-navigation").attr('title', ''); $("a#playtitle").focus(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").mouseover(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").blur(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#playtitle").mouseleave(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#play").keydown(function(ev){ if (ev.which ==27) { $("#tip1").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); $("a#stoptitle").focus(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").mouseover(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").blur(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").mouseleave(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").keydown(function(ev){ if (ev.which ==27) { $("#tip2").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); }); // End This code is added by iTalent as part of iTrack 1859082
Top Solution Authors