Forum Discussion
CALCULATE not showing correct count
- 10 years ago
hi there
I reached the solution (not the more elegant, but...)4ano = IF(SUM('f_tabelão'[PAX 4])>(CALCULATE(('d_AuxQtMáxPAX'[Qt Máx PAX contrato]);'f_tp Contrato FPSO'[Tp Contrato (anos)]=4));CALCULATE(((SUM('f_tabelão'[PAX 4])-('d_AuxQtMáxPAX'[Qt Máx PAX contrato]))*'d_custos vôos extras'[PAX Extra (só convert R$)]);'f_tp Contrato FPSO'[Tp Contrato (anos)]=4);0)
f_tabelão'[PAX 4] -> Unfortunately, I needed to create different columns for each year...
i there
Tks, I'll try to do this in English.
I do have a (giant) table with PAX flown dates and destinies (fig 1), and for each destiny I do have a maximum contract allowance (like a “pre-paid PAX flights”).
I need to check and SUM the PAX amount that were over the contract allowance for each year and per destiny. * obs: when we do have total flights bellow this contract allowance, this “credit” is not cumulative for the next period.
So, I can SUM the total PAX per year and per destiny (no problem), but when I try to calculate for a long period (such as 5 years), the Power BI calculate with the total allowance (ex: 5 x each year allowed) by the total PAX.
And I need to know the total extra-cost.
What can I do?
The simplest thing to do is to turn your Measure into a Column. So if you had a related table of just "ano 1", "ano 2", etc. relate that to your other table and use RELATEDTABLE function to perform the calculation for each year. Then, you could just use that column in a table visualization along with the year and you are all set as Columns behave the way you would expect in tables.
Another option is to use HASONEFILTER(table[ano]) in your original measure calcuation. So, for example:
extra-franquia = IF(HASONEFILTER(ano[ano]),IF(SUM(ano[amount])<1000,0,SUM(ano[amount])-1000),-100)
This will return -100 in the Total row because that row does not have only one filter for ano[ano] column (I named my table "ano"). Now, what that calculation would be, not sure because you can't SUM an measure but if you can come up with the right formula for the Total row for the measure, that is how you could do it.
- Greg_Deckler10 years ago
Community Champion
This just might do it:
extra-franquia = IF(HASONEFILTER(ano[ano]),IF(SUM(ano[amount])<1000,0,SUM(ano[amount])-1000),SUMX(FILTER(ano,[amount]>1000),[amount]-1000))
- nonick54210 years agoRegular Visitor
hi there
I reached the solution (not the more elegant, but...)4ano = IF(SUM('f_tabelão'[PAX 4])>(CALCULATE(('d_AuxQtMáxPAX'[Qt Máx PAX contrato]);'f_tp Contrato FPSO'[Tp Contrato (anos)]=4));CALCULATE(((SUM('f_tabelão'[PAX 4])-('d_AuxQtMáxPAX'[Qt Máx PAX contrato]))*'d_custos vôos extras'[PAX Extra (só convert R$)]);'f_tp Contrato FPSO'[Tp Contrato (anos)]=4);0)
f_tabelão'[PAX 4] -> Unfortunately, I needed to create different columns for each year...