Matrix Power BI totals are not calculated - matrix

the sub-totals and grand-totals of the CA facturé, of the provision sur CA return 0 for the Dimfi project code which contains several lines.
On the other hand, for the Dimfi project code which contains a single line, the subtotal is displayed correctly.
Here is a formula I used
CA Facturé =
IF(
OR(
CONTAINSSTRING(SELECTEDVALUE('ECRITURE COMPTABLE'[N° de document]),"AV")
,CONTAINSSTRING(SELECTEDVALUE('ECRITURE COMPTABLE'[N° de document]),"VT")
)
,[Solde]
,0
)
enter image description here
enter image description here
when i replaced SELECTEDVALUE() by MAX() it gaves this result, the total of CA FACTURE is incorrect

Some ideas before for measure commenting.
DAX calculates result separately for each row you have in the matrix.
On a screenshot you have 23 rows, so the measure calculates 23 times. Each row has it own context (some values that affect the result).
When DAX calculates row - 1, the context of calculation is Dimfi code project = E002P00019-01
So DAX filters your table before measure returns you a value like this:
CALCUATE(
[CA Facturé] -- the body of the measure works after filtering
,'ECRITURE COMPTABLE'[Dimfi code project] = "E002P00019-01"
-- the table consist of unique [Dimfi code project] value
-- and multiple dependent [N° de document] values that are hidden in the matrix.
)
When DAX calculates row - 6, the context of the calculation is Dimfi code project = E002P00021-01 and [N° de document]=AVPREE0020001795
So DAX filters your table before measure returns you a value like this:
CALCUATE(
[CA Facturé]
,'ECRITURE COMPTABLE'[Dimfi code project] = "E002P00021-01"
,'ECRITURE COMPTABLE'[N° de document]="AVPREE0020001795"
-- the table consist of unique [Dimfi code project] value
-- and unique [N° de document] value
-- may be you get a table with 1 row
)
For Total you have all table for the measure. The table is not filtered.
Now comments:
CA Facturé =
I want to collect all visible in the context unique values for [N° de document] with VALUES() function.
It's about the same as DISTINCT(),
but DISTINCT() excludes blank values from the result.
VALUES() will return all unique values (codes) for total row in the matrix,
multiple [N° de document] for rolled up [Dimfi code project],
1 value if you see [N° de document] in the matrix row:
VAR docNumValues = VALUES('ECRITURE COMPTABLE'[N° de document])
docNumValues is a table with 1 column and all unique [N° de document] that are visible in the context
for row 5 of the matrixit it looks like this:
N° de document
AVPREE0020001795
REPOE0020001164
VTPRE0020009986
...
VTPRE0020018283
ADDCOLUMNS in this measure creates a virtual table.
It consist of as that much row as you have unique [N° de document] values in a certain row of matrix.
ADDCOLUMNS is an iterative function it means that goes through each row
of base table docNumValues and evaluate an expression that is presented after new column name.
the first iteration of ADDCOLUMNS will add a filter to CALCULATE like this:
CALCULATE(
IF(...
)
,`[N° de document]=AVPREE0020001795`
)
and CALCULATE will cut a table for calculation with a 1 unique value.
VAR withSum =
ADDCOLUMNS(
docNumValues
,"#Sum",CALCULATE( -- adds filter `[N° de document]=...
IF(
OR(
LEFT(
SELECTEDVALUE('ECRITURE COMPTABLE'[N° de document])
,2
)="AV"
,LEFT(
SELECTEDVALUE('ECRITURE COMPTABLE'[N° de document])
,2
)="VT"
)
,[Solde]
,0
)
)
)
AS a result of the ADDCOLUMNS() for row 5 of the matrix you will have a virtual table withSum like this:
N° de document
#Sum
AVPREE0020001795
-5823.10
REPOE0020001164
0
VTPRE0020009986
10 493.55
...
...
VTPRE0020018283
5505.07
Than you just make a summation of all values that you have in the table.
RETURN
SUMX(withSum,[#Sum])
I used LEFT() instead of CONTAINSSTRING(), because it's safety - it can be that you will have the code like RTVT, and CONTAINSSTRING() will return TRUE()

Related

If a record doesn't not exist in table (filters applied), I want my && function to return 1 in DAX measure

I have added image which will describe data and matrix i want to create
I have to use simple DAX to show if vehicle has taken a trip and it has not refueled that day. So it should return 1 in my measure.
I am using IF Table 1[Miles]>1 && Table2 [fuel]<0 , it should return 1, filters (Date and Vehicle Number). it returns blank in my matrix
The day vehicle doesnt refill , no record is entered, so if i check data behind, apply date filter , i donot get any rows.
I want my DAX to return 1 if it doesnt find any record
According to the fuel not being negative, At most zero, and based on this condition:
Here is the relationship formed [Vehicle ID]:
Also you need to enter data for Car ID2 Fuel information:
Now You need to create your measure to use in matrix visual:
YourMeasure = CALCULATE(
SUMX('Data Table2',
IF(RELATED('Data Table1'[Miles])>1 && 'Data Table2'[Fuel]= 0, 1)))
And finally test it on the visual:

PowerBI - Pivot Rows on Matrix Visualization - Month + 1

I have a dataset in the following format. Notice InitialDate of July
2022 has 1 corresponding row of RollingDate and Churn, June 2022 has
2 corresponding rows, May has 3 etc etc
Which I'm looking to display the results in a table matrix like this.
The issue I'm finding it is that if I just use RollingDate as the
Columns and Churn as the Values, it looks like this
But what I want is this
Add a Rank column to the table as follows:
Rank =
VAR __InitialDate = 'Table'[InitialDate]
RETURN
RANKX(
FILTER( Table , Table[InitialDate] = __InitialDate ),
Table[RollingDate],
,ASC
)-1

How do I average a column of values filter by categories? In Power Bi

So I have a table that have a column with values and an other with the category "National" or "International".
I need to calculate the average percentage of the values in the national category! And only return the value in % so that i can see it on a card.
Example of the data i have
Need to see it in a visual like this
National =
CALCULATE(
COUNTA('SEGUIMIENTO'[Tipo]),
'SEGUIMIENTO'[Tipo] IN { "Nacional" }
)
%National =
DIVIDE(
[National],
COUNTA('SEGUIMIENTO'[Tipo])
)

Different number of rows for different columns per page

I have a SSRS report in which there are 3 columns each contain 3 different subreports in a table. Requirement is 1st subreport column should return 27 rows, 2nd : 25 rows and 3rd:26 rows. Is it possible in SSRS ? If yes How ?
You can do this.. using row_number and Mod.
I'm simply generating a list of numbers from 1 - 100 below.. lets assume that this is your dataset. Create a new column using row_number and partition it by mod 25 (27 or 26 as you require) against this dataset. Now you have a unique value every X number of rows..
declare #start int = 1
declare #end int = 100
;with mycte as (
select distinct n = number
from master..[spt_values]
where number between #start and #end
)
Select
*
,ROW_NUMBER() OVER (PARTITION BY (mycte.n % 25) ORDER BY (n) )rn
from mycte
order by 1,2
Now in SSRS, against each subreport add this column, add a parent group, grouping by this newly generated row number (RN in this case). Remove any columns that SSRS adds after grouping, but keep the grouping..
Set the group property to pagebreak in between each instance of the groups.. Done!

How to get all the parameters that are selected as a rows using row groups in SSRS matrix report?

I need to get all the values(Suppose Jurisdiction) that are selected in the Parameter(Multi value Parameter). My Stored Procedure is only returning few jurisdictions as the tables are only having that data. But I need to show the other jurisdictions that are selected as input parameters with Null or 0 for the corresponding values.
Like if I selected NJ,VA,IA,NY and my SP for report dataset is getting values for NJ,VA,IA from the table I need to represent these with table values and the NY with Spaces or 0.
Now I am getting
Jurisdiction Value
NJ 1
VA 23
IA 5
But I need to get
Jurisdiction Value
NJ 1
VA 23
IA 5
NY 0 or Null
Jurisdiction is used as the row group in SSRS matrix report.
There are two approaches here.
Firstly, if you can alter the stored procedure or write your own SQL for your dataset, then you can do this with a left outer join. For instance, your SQL probably looks something like this:
SELECT Jurisdiction, Value
FROM JurisdictionValues
WHERE Jurisdiction IN (#Jurisdictions)
This only gives you results that have values. If we left outer join that against the Jurisdictions table then we can return something for all the parameter values selected, even if the value will be null.
SELECT J.Jurisdiction, JV.Value
FROM Jurisdictions J
LEFT OUTER JOIN JurisdictionValues JV ON J.Jurisdiction = JV.Jurisdiction
AND J.Jurisdiction IN (#Jurisdictions)
The other way to do it is to do a lookup in SSRS directly. You will have two datasets, one being Jurisdictions and the other JurisdictionValues. The table for the report is based on Jurisdictions and has the following SQL:
SELECT Jurisdiction
FROM Jurisdictions
WHERE Jurisdiction IN (#Jurisdictions)
The JurisdictionValues table returns the jurisdictions and values from your stored procedure. In the table cell for the value, put the following formula:
=Lookup(Fields!Jurisdiction.Value, Fields!Jurisdiction.Value, Fields!Value.Value, "JurisdictionValues")
The Lookup finds the corresponding value for the Jurisdiction and returns the Value field.

Resources