Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello, maybe it is something easy, but I do not find the formulas to make me the count and sum that I look for on a table under certain criteria, to see if you can help me with the following:
I have a table of book stores, in this example I have put very few provinces to summarize data, but they would be stores distributed in all the provinces of Spain:
I want to get to the result that I put a little below where, according to the typology described in the last Column and by Provinces, tell me numbers of Stores and add number of books, so that the "Paper + Digital Typology" would be a total by province of everything there is (both Paper + Digital + Only Digital) and on the other hand it would be Only Digital that would be a count of centers and a sum of books of only those stores that do not have paper books.
Here's the result in excel of what I want to get a Power Bi table:
As I said before, it is really about many provinces and I do not think the solution is to filter specifically by the name of each of them, surely there is a way to do it but I am a beginner and I do not find the formulas.
Greetings and thanks in advance
Solved! Go to Solution.
Hi @Syndicate_Admin ,
Here are the steps you can follow:
1. In Power query. Add Column – Index Column – From 1.
2. Create measure.
Ndetiendas =
var _indexTIP=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])))
var _indexplus1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
var _indexnegative1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))
return
SWITCH(
TRUE(),
_indexTIP <> _indexplus1 && _indexTIP <> _indexnegative1 ,MAX('Table'[Toal Libros]),
_indexTIP =_indexplus1&&MAX('Table'[Index])<>MINX(ALL('Table'),'Table'[Index]) ,CALCULATE(SUM('Table'[Toal Libros]),FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia]))),
_indexTIP =_indexplus1&&MAX('Table'[Index])=MINX(ALL('Table'),'Table'[Index]) ,MAX('Table'[Toal Libros]),
_indexTIP =_indexnegative1,CALCULATE(SUM('Table'[Toal Libros]),FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia]))))Ndelibros =
var _indexTIP=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])))
var _indexplus1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
var _indexnegative1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))
return
SWITCH(
TRUE(),
_indexTIP <> _indexplus1 && _indexTIP <> _indexnegative1 ,COUNTX(FILTER(ALL('Table'),'Table'[Tipologia]=MAX('Table'[Tipologia])&&'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexplus1&&MAX('Table'[Index])<>MINX(ALL('Table'),'Table'[Index]) ,COUNTX(FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexplus1&&MAX('Table'[Index])=MINX(ALL('Table'),'Table'[Index]) ,COUNTX(FILTER(ALL('Table'),'Table'[Tipologia]=MAX('Table'[Tipologia])&&'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexnegative1,COUNTX(FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia])
)
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @Syndicate_Admin ,
Here are the steps you can follow:
1. In Power query. Add Column – Index Column – From 1.
2. Create measure.
Ndetiendas =
var _indexTIP=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])))
var _indexplus1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
var _indexnegative1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))
return
SWITCH(
TRUE(),
_indexTIP <> _indexplus1 && _indexTIP <> _indexnegative1 ,MAX('Table'[Toal Libros]),
_indexTIP =_indexplus1&&MAX('Table'[Index])<>MINX(ALL('Table'),'Table'[Index]) ,CALCULATE(SUM('Table'[Toal Libros]),FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia]))),
_indexTIP =_indexplus1&&MAX('Table'[Index])=MINX(ALL('Table'),'Table'[Index]) ,MAX('Table'[Toal Libros]),
_indexTIP =_indexnegative1,CALCULATE(SUM('Table'[Toal Libros]),FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia]))))Ndelibros =
var _indexTIP=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])))
var _indexplus1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
var _indexnegative1=CALCULATE(MAX('Table'[Tipologia]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))
return
SWITCH(
TRUE(),
_indexTIP <> _indexplus1 && _indexTIP <> _indexnegative1 ,COUNTX(FILTER(ALL('Table'),'Table'[Tipologia]=MAX('Table'[Tipologia])&&'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexplus1&&MAX('Table'[Index])<>MINX(ALL('Table'),'Table'[Index]) ,COUNTX(FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexplus1&&MAX('Table'[Index])=MINX(ALL('Table'),'Table'[Index]) ,COUNTX(FILTER(ALL('Table'),'Table'[Tipologia]=MAX('Table'[Tipologia])&&'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia]),
_indexTIP =_indexnegative1,COUNTX(FILTER(ALL('Table'),'Table'[Provincia]=MAX('Table'[Provincia])),[Provincia])
)
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi,
Assuming that your input data is in a Power BI table named Book Stores, you can use the following method:
a) Create a measure Mesmm like this:
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 43 | |
| 39 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 68 | |
| 63 | |
| 31 | |
| 30 | |
| 23 |