1"use strict";(self.webpackChunkholistics_docs=self.webpackChunkholistics_docs||[]).push([["15239"],{43789(e,n,r){r.r(n),r.d(n,{metadata:()=>i,default:()=>u,frontMatter:()=>a,contentTitle:()=>s,toc:()=>l,assets:()=>o});var i=JSON.parse('{"id":"docs/modeling/dynamic-metric-definition/dynamic-currency-conversion","title":"Dynamic Currency Conversion","description":"Learn how to let users view metrics in different currencies using parameter fields","source":"@site/docs/docs/modeling/dynamic-metric-definition/dynamic-currency-conversion.md","sourceDirName":"docs/modeling/dynamic-metric-definition","slug":"/docs/modeling/dynamic-metric-definition/dynamic-currency-conversion","permalink":"/docs/modeling/dynamic-metric-definition/dynamic-currency-conversion","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"title":"Dynamic Currency Conversion","description":"Learn how to let users view metrics in different currencies using parameter fields","sidebar_label":"Dynamic Currency Conversion","slug":"/docs/modeling/dynamic-metric-definition/dynamic-currency-conversion"},"sidebar":"docs","previous":{"title":"Dynamic Metric Conditions","permalink":"/docs/modeling/dynamic-metric-definition/dynamic-metric-condition"},"next":{"title":"Dynamic Top N","permalink":"/docs/modeling/dynamic-metric-definition/dynamic-top-n"}}'),c=r(74848),t=r(28453);let a={title:"Dynamic Currency Conversion",description:"Learn how to let users view metrics in different currencies using parameter fields",sidebar_label:"Dynamic Currency Conversion",slug:"/docs/modeling/dynamic-metric-definition/dynamic-currency-conversion"},s,o={},l=[{value:"Introduction",id:"introduction",level:2},{value:"Example: Multi-Currency Revenue Display",id:"example-multi-currency-revenue-display",level:2},{value:"Step 1: Create a Currency Parameter Model",id:"step-1-create-a-currency-parameter-model",level:3},{value:"Step 2: Define Dynamic Metric with Currency Conversion",id:"step-2-define-dynamic-metric-with-currency-conversion",level:3},{value:"Step 3: Create Dashboard Currency Selector",id:"step-3-create-dashboard-currency-selector",level:3},{value:"See Also",id:"see-also",level:2}];function d(e){let n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,t.R)(),...e.components};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(n.admonition,{title:"knowledge checkpoint",type:"tip",children:[(0,c.jsx)(n.p,{children:"A grasp of these concepts will help you understand this documentation better:"}),(0,c.jsxs)(n.ul,{children:["\n",(0,c.jsx)(n.li,{children:(0,c.jsx)(n.a,{href:"/docs/modeling/param-fields",children:"Parameter Fields"})}),"\n",(0,c.jsx)(n.li,{children:(0,c.jsx)(n.a,{href:"/reference/aql/expression",children:"AQL Expression"})}),"\n"]})]}),"\n",(0,c.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,c.jsx)(n.p,{children:"Dynamic currency conversion allows users to view revenue and other monetary metrics in their preferred currency. Instead of creating separate metrics for each currency, you can use parameter fields to let users switch currencies on-the-fly from a dashboard filter."}),"\n",(0,c.jsx)("figure",{class:"video-container",children:(0,c.jsx)("iframe",{width:"560",height:"315",src:"https://www.youtube.com/embed/XpKeox-WUmk?si=A07c9HXFO1ku7iMm&autoplay=1&mute=1&loop=1&playlist=XpKeox-WUmk",title:"YouTube video player",frameborder:"0",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",referrerpolicy:"strict-origin-when-cross-origin",allowfullscreen:!0})}),"\n",(0,c.jsx)(n.h2,{id:"example-multi-currency-revenue-display",children:"Example: Multi-Currency Revenue Display"}),"\n",(0,c.jsx)(n.p,{children:"Suppose you have an international e-commerce platform and want users to view revenue in their preferred currency (MYR, USD, or THB)."}),"\n",(0,c.jsx)(n.h3,{id:"step-1-create-a-currency-parameter-model",children:"Step 1: Create a Currency Parameter Model"}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-aml",metastring:'title="currency_param.model.aml"',children:"Model currency_param {\n type: 'query'\n label: 'Currency Parameter'\n data_source_name: 'your_datasource'\n\n query: @sql select 1 ;;\n\n //highlight-start\n param currency {\n label: 'Display Currency'\n type: 'text'\n allowed_values: ['USD', 'MYR', 'SGD', 'THB', 'VND', 'AUD']\n }\n //highlight-end\n}\n"})}),"\n",(0,c.jsx)(n.h3,{id:"step-2-define-dynamic-metric-with-currency-conversion",children:"Step 2: Define Dynamic Metric with Currency Conversion"}),"\n",(0,c.jsx)(n.p,{children:"Add the parameter model to your dataset and create a metric that switches calculation based on the selected currency."}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-aml",metastring:'title="ecommerce.dataset.aml"',children:"Dataset ecommerce {\n label: 'Ecommerce'\n data_source_name: 'your_datasource'\n\n models: [orders, currency_param]\n\n // Base metric in original currency\n metric gmv {\n label: 'GMV (Original Currency)'\n type: 'number'\n definition: @aql sum(orders.value) ;;\n }
1\n\n //highlight-start\n // Dynamic metric that converts to selected currency\n metric gmv_converted {\n label: 'GMV (Converted)'\n type: 'number'\n definition: @aql case(\n when: 'USD' in currency_param.currency, then: gmv * 1,\n when: 'MYR' in currency_param.currency, then: gmv * 4.47,\n when: 'SGD' in currency_param.currency, then: gmv * 1.35,\n when: 'THB' in currency_param.currency, then: gmv * 35.5,\n when: 'VND' in currency_param.currency, then: gmv * 25450,\n when: 'AUD' in currency_param.currency, then: gmv * 1.57\n ) ;;\n // the above conversion rate might be adjusted in the future\n }\n //highlight-end\n}\n"})}),"\n",(0,c.jsx)(n.h3,{id:"step-3-create-dashboard-currency-selector",children:"Step 3: Create Dashboard Currency Selector"}),"\n",(0,c.jsxs)(n.ol,{children:["\n",(0,c.jsxs)(n.li,{children:["Add a dashboard filter linked to ",(0,c.jsx)(n.code,{children:"currency_param.currency"})]}),"\n",(0,c.jsx)(n.li,{children:"Configure the filter as single-select (since the case statement expects one value)"}),"\n",(0,c.jsx)(n.li,{children:"Set a default value (e.g., 'USD') to ensure the metric always has a valid calculation"}),"\n"]}),"\n",(0,c.jsx)(n.p,{children:"Users can now switch between currencies, and the revenue metric will automatically display values in their selected currency."}),"\n",(0,c.jsx)(n.h2,{id:"see-also",children:"See Also"}),"\n",(0,c.jsxs)(n.ul,{children:["\n",(0,c.jsxs)(n.li,{children:[(0,c.jsx)(n.a,{href:"./dynamic-metric-condition",children:"Dynamic Metric Conditions"})," - For filtering metrics"]}),"\n",(0,c.jsx)(n.li,{children:(0,c.jsx)(n.a,{href:"/docs/modeling/param-fields",children:"Parameter Fields"})}),"\n"]})]})}function u(e={}){let{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,c.jsx)(n,{...e,children:(0,c.jsx)(d,{...e})}):d(e)}},28453(e,n,r){r.d(n,{R:()=>a,x:()=>s});var i=r(96540);let c={},t=i.createContext(c);function a(e){let n=i.useContext(t);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(c):e.components||c:a(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.