DAX Dynamic Banding | Calculated Member based on Calculated Field

Good morning,
I've created a Power Pivot model that measures the blood glucose levels of clinical patients at specific times of the day. The requirement is that this metric, let's call it GlucoseLevel, is always averaged as it wouldn't make sense to sum up the values.
To meet this first requirement, I set the "Summarize By" property of the GlucoseLevel column to "Average".
The second requirement is to band the GlucoseLevel values so that groups of people can be measured by this band rather than by the individual measure values. I created a banding table in Excel and then imported it into the Power Pivot model. The banding table
has three columns (BandName, MinValue and MaxValue) and has the following values:
VERYLOW: Min Value = 0; Max Value = 3.99
OK: Min Value = 4; Max Value = 6.99
WARNING: Min Value = 7; Max Value = 10.99CRITICAL: Min Value = 11; Max Value = 30.00
It is at this point where I face my challenge. I have a GlucoseLevel measure and I have a banding table. Great. The challenge is: How do I create a calculated, dynamic
member that will look at my GlucoseLevel measure (at whatever level), do a lookup to my banding table, and then return the "BandName" column from the Banding table at that specific level? So to clarify what I mean by level: I want to be able
to view the bandings at Year level, or a Month level, or even at a week level. Then depending on what level I am at, my measure should have a Band associated to it.
I've tried to solve this issue in a couple of ways:
Attempt 1
Create a calculated column in my fact table that contains a nested IF statement to manually band my GlucoseLevel values. This works fine if I view my data at the lowest level of granularity, however
it does not work if I start looking at my data at the day, week, month etc. levels
Attempt 2
1.) Create a calculated field (not a calculated column) that averages my GlucoseLevel measure. This is cool because it will average my measure at whatever level I am viewing it at. Let's call
this field Bob...
2.) Band my measure Bob by creating another calculated field (called PatientBand). This field uses my banding table (described earlier) in conjunction with my calculated field Bob. This works perfectly, except for one big flaw: Excel sees this banding field
as a measure, and not as something that I can use as a column / row...
So my question is: Can I trick Excel into viewing my PatientBand calculated field as an attribute, and not as a measure? And if not, how do I get around this challenge? Here is the DAX formula that I used to create my second calculated field "PatientBand":
PatientBand:=CALCULATE(
    VALUES (Bandings[BandName]);
    FILTER (
        Bandings; 
        Test[Bob] >= Bandings[MinValue]
     && Test[Bob] <= Bandings[MaxValue]
Thanks!

So there are 2 ways that I can think of for doing that.
1) if you are only using MDX clients like Excel or Reporting services you can create a text based measure that returns the banding name. (Note that this sort of approach does not work at the moment with PowerView as it only displays numeric measures). This
would effectively let you show a label next to a reading as opposed to moving the reading under a given banding column.
Banding Name :=
CALCULATE (
    VALUES ( Bands[BandName] ),
    FILTER (
        Bands,
        [Average of GlucoseReading] >= Bands[BandMin]
            && [Average of GlucoseReading] <= Bands[BandMax]
            && NOT ( ISBLANK ( [Average of GlucoseReading] ) )
2) This next approach will show the results exactly as you had them in your sample screenshots. It just takes a slight bending of the DAX. I'm using a SUMX here, not because I want to sum anything, but because the "X" version of SUMX basically loops over
every row in the specified table and sums the expression in the second parameter. I have setup the second parameter so that it only returns a single value for the average if it is in the appropriate banding. 
Banded Average:=IF (
    HASONEVALUE ( Bands[BandName] ),
    SUMX(
        'Bands',
        IF (
            NOT ( ISBLANK ( [Average of GlucoseReading] ) )
                && [Average of GlucoseReading] >= MIN ( Bands[BandMin] )
                && [Average of GlucoseReading] <= MIN ( Bands[BandMax] ),
            AVERAGE(Readings[GlucoseReading]),
            BLANK()
,AVERAGE(Readings[GlucoseReading])
http://darren.gosbell.com - please mark correct answers

Similar Messages

  • Dynamic Date Calculation for Current Date - 1

    I am trying to create a variant with a dynamic date calculation attribute.
    I am following the instructions as they are posted to the web but I get an error message.
    I want to get all data EQ to the current date -1
    In the object for selection screen I enter a D for Selection Variable, for Name of Variable I enter an I to include specific values and the option EQ for current date +/- ??? days.  Then I enter 1- for the number of days.  I have tried to enter this many times and in many ways but it doesn't work.  I keep getting this message "lower limit of interval is greater than upper limit"

    Hi,
    Welcome to SDN.
    Selection-screen has four values -
    SIGN
    OPTION
    LOW
    HIGH
    Pass your date value in the option low for the screen.
    Sign you have already pass as I and option as EQ.
    Regard,
    Amit
    Reward all helpful replies.
    Can you paste your code here.
    Message was edited by:
            Amit Khare

  • How to use Dynamic date calculation in some transactions.

    Hello everyone.
    I have to create some dynamic variants using the dynamic date calculation. The problem is that in some transactions it´s not possible to use some variables that can round a value. For example: in transaction /SAPAPO/MC90, I need to fix 3 months in the horizon like this: From date: 01.01.2009  To date 31.03.2009. The current month is 01.01.2009. Next month the current month will be february, so the horizon would be 01.02.2009 to 30.04.2009.
    In 5.1 version, it´s impossible to fix the months, because the options that appear in the match code are:
    Current Date
    Current date +/- ??? days
    current date +/- ??? work days
    First day of current month
    nth working day of current month
    First day of next month
    First day of previous month
    Last day of previous month
    Last Day of the Current Month
    Does anybody knows how to do this? This is happening in other transactions to.
    Thanks a lot
    Regards
    Angela

    I am not sure where you are looking for..but here is what I can do it in MC90 Tcode:
    1. when you try to save the variant, in the variant screen check the two boxes under "Current date" field for Selection Variables attributes "L"
    2. Then click on Selection variables option and click on the "D" variable so that it turns to green
    3. Drop down in the first current date field, select "Current +/- ??? days. here if you want to start from today's date maintain 0 days
    4. In the second Current date field maintain 90 days in "Current +/- ??? days.
    5. save it
    please let me know if I misunderstod the issue

  • Fiscal Calendar in Report Variant Dynamic Date Calculation

    We are switching from the standard calendar to a 4/4/5 calendar for our fiscal calendar. We have a number of batch reports that use dynamic date calculation in the variant to get Month-To-Date or Previous Month date ranges. Is there a way to convert these variants to use the new FiScal calendar instead of the regular calendar?

    thanks to answer , praveen.
    I know, VARI has name of FM , but not has Calendar ID.

  • Calculated fields based on data in multiple rows

    Hi,
    I am using SOA Suite 11.1.1.4 for BAM.
    Can someone please help explain to me if and how we can use calculated fields in BAM data objects where the calculations are not only based on the data for that row, but on multiple rows ?
    Like for example, this case can easily be constructed -->
    TestDataObject Layout
    Column1 integer
    Column2 integer
    Column3 calculated = Column1 + Column2
    But if I want to create something like this -->
    TestDataObject Layout
    Column1 integer
    Column2 integer
    Column3 calculated = max(Column1) + avg(Column2)
    Is it possible to do the above ?
    Is it possible to check multiple rows of the other columns while calculating a value ?
    Thanks & Regards,
    Karan.
    Edited by: user8890668 on Mar 9, 2011 3:58 AM

    Hi, Karan.
    Do you know you can do that in reports with calculated fields?
    I guess it is not possible using calculating functions offered in data objects to do that.
    If you, or anybody, discover how do that, please tell us. I would like to know that.
    Luciano Gomes
    user8890668 wrote:
    Hi,
    I am using SOA Suite 11.1.1.4 for BAM.
    Can someone please help explain to me if and how we can use calculated fields in BAM data objects where the calculations are not only based on the data for that row, but on multiple rows ?
    Like for example, this case can easily be constructed -->
    TestDataObject Layout
    Column1 integer
    Column2 integer
    Column3 calculated = Column1 + Column2
    But if I want to create something like this -->
    TestDataObject Layout
    Column1 integer
    Column2 integer
    Column3 calculated = max(Column1) + avg(Column2)
    Is it possible to do the above ?
    Is it possible to check multiple rows of the other columns while calculating a value ?
    Thanks & Regards,
    Karan.
    Edited by: user8890668 on Mar 9, 2011 3:58 AM

  • D: Dynamic date calculation

    Hello,
    In BEx, when creating a variant, is it possible to use "Selection variable = D: Dynamic date calculation"?
    I have created a variable for 0calmonth and in the Variant Attributes screen, Selection variable field, the only option is T: Table Variable from TVARVC.
    BW version 3.5
    Thanks for any information you can provide.
    Mark

    Hi,
    have a look at the below link..  ( they have mentioned the steps of customer exit variable fassigning for reporting agent)
    https://websmp110.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700003598422003E
    Regards,
    Siva.

  • Enable "dynamic date calculation" variable type

    When saving reporting date/period in a report variant, we may use "dynamic date calculation" to specific date as selection parameter.  But the "Dynamic date calculation" is not visible in some ABAP reports - only "Table Variable from TVARVC"  type is available for selection. 
    For those reports that are missing that variable type, how can we enable the "Dynamic date calculation" variable type to be visible?

    Hi Paco:
    Yes, they are z-reports, both have the same almost everything, created by the same ABAPer, for the same application SD, just grouping the data differently.
    It seems a screen (#100?) is missing,  In the old version, it's screen 100 where to activate the "D" and "B" variable types.  Now it goes to screen 281.
    Stacy

  • Dynamic Date Calculation

    Hi all,
    Currently, i need to run a background PO report daily. As i only want today's PO data everytime the background job runs, i set the PO date dynamically using dynamic date calculation choosing current date, save it as a variant then schedule daily run.
    Howerver, for the next run day, the report was ok but subsequent running, the report is not the current date data.
    Any idea where i have miss out?
    Kindly assist and advise, points will be rewarded.
    Regards,
    Eric

    Hi,
    Thanks for your prompt reply.
    I am looking for ways to create a variant with changing date for daily run so that i do not have to daily modify the date.
    Regards,
    eric

  • Dynamic date calculator

    Hi all
    In Variants we can give dynamic date calculator to calculate date as we required. Does there is a option to add more selection option (ie if I have to add a selection last day of next month). Where I can do this
    Please comment
    With Regards
    Arun

    check the LSVAVF01 program for enchancement. or dynamic date selection you can select "  nth working day of current month " with calender option to select the last date of month.

  • Activating dynamic date calculation in variant

    Per the link below, I used to be able to activate "dynamic date calculation" in variant.
    <link to blocked site removed by moderator>
    Our system has been upgraded to 6.0 and now we do not the same variant attribues screen where I can activate the "D" variable.  It brings me to program/screen SA38/281. 
    Any suggestion how I may activate the "D" dynamic date calculation variable in a variant?
    Edited by: Thomas Zloch on Oct 14, 2011 11:34 AM

    Actually I meant the relevant code of your custom report, you just provided me with the info of the standard variant screen.
    You can go to SE38, enter your custom report name, display the code, and paste the definition of that parameter. (It would be something like
    PARAMETERS: P_DATEHG TYPE XXX_TYPE.
    What I am interested in is to know which data type is being used, since this functionaliy will only apply to date type fields. So, bottom line: this field must definitely be a date, which makes me think that either something has changed in the custom report or after the upgrade to ECC 6.0 this data type might have changed as well.
    Best regards.
    Edited by: Jose Maria Otero on Oct 14, 2011 5:26 PM

  • Variant with Dynamic Date Calculation

    I have a variant that includes a dynamic date calculation.  I'm using the Current day -1 date calculation. Does the dynamic date calcuation use the time zone of the system or the time zone designated on the user id for the calcuation?

    time zone of the system.. if you want to use the user time use Sy-timlo

  • How to change the column value which is coming from DO by a calculated field?

    Hi all,
    I want to change a column value based on my calculated field value. I have a column which is coming from DO which is based on External Data Source. I have a calculated field in my report. When there is any change in the calculated field then the column which is coming from DO needs to be changed. It means the DO needs to get updated when there is a change in the calculated field. Or like if the calculated field meets some condition then I need to change/update the same in the DO. This has to be done on the fly. the report should not submitted for this. when there is a change in the calculated column the DO column needs to get updated.
    Thanks,
    Venky.

    Ok, I've been a customer for very many years, I'm on a fixed retirement
    income.  I need to reduce my bills, my contract ends in  Dec. I will be
    pursuing other options unless I can get some concessions from Verizon.  My
    future son-in-law was given this loyalty plan, so I know this is a
    reasonable request.  My phone number is (removed)  acct number
    (removed)
    >> Personal information removed to comply with the Verizon Wireless Terms of Service <<
    Edited by:  Verizon Moderator

  • SSRS Using WHERE in a calculated field

    Hi All,
    Im having a real issue with something that seems like it should be easier than it is.
    In my tablix I want to add the expression =Sum(Fields!ID20.Value)-Sum(Fields!ID20.Value) BUT I need to determine if another criteria is met.
    EG - I want =Sum(Fields!ID20.Value WHERE [InOut]="In")-Sum(Fields!ID20.Value WHERE [InOut]="Out")
    Many Thanks for any help

    Hi LB79,
    In Reporting Services, Aggregate functions cannot be used in calculated field expressions, since the data for calculated fields will be based on individual rows not on group basis. As a workaround, we can directly add the expression to a textbox of the tablix
    instead of using that calculated field. For detail information, please refer to the following steps:
    Right click the text box which you want to insert the calculated field, then click Expression.
    In the Expression text box, refer to the following expression:
    =sum(iif(Fields!InOut.Value ="In", Fields!ID20.Value,0),"DataSet_name")-sum(iif(Fields!InOut.Value ="Out", Fields!ID20.Value,0),"DataSet_name")
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Updatable property of Calculated Field in ViewObject does not work

    Hello,
    I have set the Updatable property of some ViewObject attributes to "while new".
    In the page those attributes are shown as <af:inputListOfValues> components.
    When creating a new row, those components properly appear as enabled and let me insert any values, since the row is new.
    However, after a following commit, once the table in the page is refreshed, I still see some components enabled on the row I committed before. This only happens with attributes based on calculated fields, not with those based on real table fields, as if the "while new" property specified on the ViewObject calculated fields was ignored.
    Do you know why? Is there a solution or work around?
    Below are the ViewObject XML section and the af:component definition based on the attribute.
    <ViewAttribute
    Name="Cod"
    IsPersistent="false"
    PrecisionRule="true"
    Precision="15"
    Type="java.lang.String"
    ColumnType="VARCHAR2"
    AliasName="COD"
    Expression="COD"
    SQLType="VARCHAR"
    IsUpdateable="while_insert"
    LOVName="LOV_Cod">
    <DesignTime>
    <Attr Name="_DisplaySize" Value="15"/>
    </DesignTime>
    <Properties>
    <SchemaBasedProperties>
    <CONTROLTYPE
    Value="input_text_lov"/>
    </SchemaBasedProperties>
    </Properties>
    </ViewAttribute>
    <af:inputListOfValues id="ilov1"
    popupTitle="Search and Select: #{bindings.BLOCK.hints.Cod.label}"
    value="#{row.bindings.Cod.inputValue}"
    model="#{row.bindings.Cod.listOfValuesModel}"
    required="#{bindings.BLOCK.hints.Cod.mandatory}"
    columns="#{bindings.BLOCK.hints.Cod.displayWidth}"
    shortDesc="#{bindings.BLOCK.hints.Cod.tooltip}"
    autoSubmit="true">
    <f:validator binding="#{row.bindings.Cod.validator}"/>
    </af:inputListOfValues>

    Helga,
    The question is what does this "require" flag do? We read the book of life (cl_htmlb_inputfield), and see that this flag only controls in the first instance a little red * that is rendered next to the input field. This is a pure visualization for the user of the page.
    In addition you can ask that a check be done in the browser. This you can do with:
      <htmlb:inputField  id = "wander"
                         value = "E"
                         required = "TRUE"
                         doValidate="true" />
    However, I would not serious recommend this. Now even if you user presses a cancel button, or link, or breadcrumb, or..., the check will still complain.
    What we currectly do (and recommend), is to set the required flag on the <htmlb:<b>label</b>/> tag. And then do the actual checking on the server (must be done in anycase). If no value, or not correct, then also set the "invalid" flag, render out error message and redo page.
    ++bcm

  • Sum of Calculated Field

    Hi,
    I am using 9.0.2.39.1 and am having trouble summing up a calculated field. I have a crosstab layout like so:
                           MTD               YTD              CURRENT YR
    2005                   $                 $                (decode function based on period)
    2004                   $                 $                (decode function based on period)
    2003                   $                 $                (decode function based on period)I put a grand total for MTD, YTD and Current YR, but it does not pick up the total sum for the Current Year calculated field. I then also tried a total just for the Current Year field, but it is just blank although that column has values for each row. Strangely the count/max..etc functions give me a value, just not sum. The calculation works perfectly just not the sum of it.
    Any idea what I am doing wrong???

    Hi,
    You need to check note 208366.1 which explains why totals can be blank. Without knowing the detail of you decode function it is hard to say what needs to be changed. Try putting a sum in front of the decode e.g.
    sum(decode(period, 'Jan period', value, 0))
    Hope that helps,
    Rod West

Maybe you are looking for

  • Smart Print not working on my HP 8500A Plus

    I installed Smart Print on my HP laptop.   One page documents are printing in multiple pages and in fragments.  The color is also missing or is out of synch.   Origin of document does not appear to matter.  Web docs and Word docs are all effected.  

  • Is there a way to speed up the response time from the dock

    Is there a way to speed up the response time for external hard drives from the dock? I have three external HDs but when I click on the alias in the dock there is always hesitation before it opens. I'm leaning towards the fact that it is just a result

  • Symbol problems and fonts

    Hi all! I have been plagued with a problem when trying to use symbols and think I have figured out what it is: Custom Fonts not loading! I'm using two custom fonts in my symbols and sometimes when I upload the project to the web, the fonts are not sh

  • "Previous iTunes Library" title. How do I remove this?

    I upgraded to iTunes 10 and when I decided to open iTunes it told me to choose a library. I chose the most recent one but noticed that some songs were missing. Right now I have organized all of my music under the iTunes folder and deleted all the oth

  • NullPointerEception... I dont get it!!!!!

    public class ItemBan{ String varName; public ItemBan() {varName = "";} public void SetVarName(String a){varName = a;} public String GetVarName(){return varName;} public class ListBan{ ItemBan[] LItemBan ; int numInList; public ListBan(){ LItemBan = n