Nested Serializers with django-rest-framework - django

I'm trying to generate a nested Json output using django-rest-framework.
But can't find the correct way to go...
Can someone please drive me to correct direction?
Thanks a lot!
--
Here are my models:
class Pacmr(models.Model):
package = models.ForeignKey(Package)
architecture = models.ForeignKey(Architecture)
component = models.ForeignKey(Component)
mirror = models.ForeignKey(Mirror)
release = models.ForeignKey(Release)
version = DebVersionField()
Package, Architecture, Component, Mirror, Release are all equivalent to:
class Package(models.Model):
name = models.CharField(max_length=50)
comment = models.CharField(max_length=200)
An example of the Pacmr table content:
SELECT id, package_id, architecture_id, component_id, mirror_id, release_id, version from pacmr_pacmr where package_id = 20671;
id | package_id | architecture_id | component_id | mirror_id | release_id | version
--------+------------+-----------------+--------------+-----------+------------+--------------
965201 | 20671 | 236 | 146 | 73 | 111 | 3.0-2.1b-1
965200 | 20671 | 236 | 146 | 73 | 109 | 3.0-2.1b-2.1
965199 | 20671 | 236 | 146 | 73 | 113 | 3.0-2.1a-5
691277 | 20671 | 236 | 146 | 73 | 105 | 3.0-2.1b-3
691276 | 20671 | 236 | 146 | 73 | 107 | 3.0-2.1b-3
691275 | 20671 | 236 | 146 | 73 | 104 | 3.0-2.1b-3
691274 | 20671 | 236 | 146 | 75 | 113 | 3.0-2.1a-5
691273 | 20671 | 236 | 146 | 72 | 111 | 3.0-2.1b-1
691272 | 20671 | 236 | 146 | 72 | 110 | 3.0-2.1b-1
691271 | 20671 | 236 | 146 | 72 | 109 | 3.0-2.1b-2.1
691270 | 20671 | 236 | 146 | 72 | 108 | 3.0-2.1b-2.1
691269 | 20671 | 236 | 146 | 72 | 113 | 3.0-2.1a-5
691268 | 20671 | 236 | 146 | 72 | 115 | 3.0-2.1a-5
691267 | 20671 | 236 | 146 | 72 | 107 | 3.0-2.1b-3
691266 | 20671 | 236 | 146 | 72 | 106 | 3.0-2.1b-3
691265 | 20671 | 236 | 146 | 72 | 104 | 3.0-2.1b-3
691264 | 20671 | 236 | 146 | 72 | 103 | 3.0-2.1b-3
691263 | 20671 | 236 | 144 | 71 | 97 | 3.0-2.1b-2.1
691262 | 20671 | 236 | 144 | 71 | 67 | 3.0-2.1b-3
691261 | 20671 | 236 | 144 | 71 | 114 | 3.0-2.1b-3
691260 | 20671 | 236 | 144 | 71 | 68 | 3.0-2.1b-3
691259 | 20671 | 236 | 144 | 71 | 101 | 3.0-2.1b-3
691258 | 20671 | 236 | 144 | 71 | 100 | 3.0-2.1b-3
691257 | 20671 | 236 | 144 | 70 | 97 | 3.0-2.1b-2.1
691256 | 20671 | 236 | 144 | 70 | 98 | 3.0-2.1b-2.1
691255 | 20671 | 236 | 144 | 70 | 67 | 3.0-2.1b-3
691254 | 20671 | 236 | 144 | 70 | 99 | 3.0-2.1b-3
691253 | 20671 | 236 | 144 | 70 | 68 | 3.0-2.1b-3
691252 | 20671 | 236 | 144 | 70 | 96 | 3.0-2.1b-3
With joins it look like this:
SELECT pacmr_pacmr.id as id, pacmr_package.name as package, pacmr_architecture.name as architecture, pacmr_component.name as component, pacmr_mirror.name as mirror, pacmr_release.name as release, version from pacmr_pacmr, pacmr_package, pacmr_architecture, pacmr_component, pacmr_mirror, pacmr_release where package_id=pacmr_package.id and architecture_id=pacmr_architecture.id and component_id=pacmr_component.id and mirror_id=pacmr_mirror.id and release_id=pacmr_release.id and package_id = 20671;
id | package | architecture | component | mirror | release | version
--------+---------+--------------+-----------+-------------------+-----------------+--------------
965201 | jvim | source | main | debian | etch | 3.0-2.1b-1
965200 | jvim | source | main | debian | lenny | 3.0-2.1b-2.1
965199 | jvim | source | main | debian | sarge | 3.0-2.1a-5
691277 | jvim | source | main | debian | sid | 3.0-2.1b-3
691276 | jvim | source | main | debian | squeeze | 3.0-2.1b-3
691275 | jvim | source | main | debian | wheezy | 3.0-2.1b-3
691274 | jvim | source | main | debian-amd64 | sarge | 3.0-2.1a-5
691273 | jvim | source | main | debian-production | etch | 3.0-2.1b-1
691272 | jvim | source | main | debian-production | etch-testing | 3.0-2.1b-1
691271 | jvim | source | main | debian-production | lenny | 3.0-2.1b-2.1
691270 | jvim | source | main | debian-production | lenny-testing | 3.0-2.1b-2.1
691269 | jvim | source | main | debian-production | sarge | 3.0-2.1a-5
691268 | jvim | source | main | debian-production | sarge-testing | 3.0-2.1a-5
691267 | jvim | source | main | debian-production | squeeze | 3.0-2.1b-3
691266 | jvim | source | main | debian-production | squeeze-testing | 3.0-2.1b-3
691265 | jvim | source | main | debian-production | wheezy | 3.0-2.1b-3
691264 | jvim | source | main | debian-production | wheezy-testing | 3.0-2.1b-3
691263 | jvim | source | universe | ubuntu | hardy | 3.0-2.1b-2.1
691262 | jvim | source | universe | ubuntu | lucid | 3.0-2.1b-3
691261 | jvim | source | universe | ubuntu | oneiric | 3.0-2.1b-3
691260 | jvim | source | universe | ubuntu | precise | 3.0-2.1b-3
691259 | jvim | source | universe | ubuntu | quantal | 3.0-2.1b-3
691258 | jvim | source | universe | ubuntu | raring | 3.0-2.1b-3
691257 | jvim | source | universe | ubuntu-production | hardy | 3.0-2.1b-2.1
691256 | jvim | source | universe | ubuntu-production | hardy-testing | 3.0-2.1b-2.1
691255 | jvim | source | universe | ubuntu-production | lucid | 3.0-2.1b-3
691254 | jvim | source | universe | ubuntu-production | lucid-testing | 3.0-2.1b-3
691253 | jvim | source | universe | ubuntu-production | precise | 3.0-2.1b-3
691252 | jvim | source | universe | ubuntu-production | precise-testing | 3.0-2.1b-3
(29 rows)
Here an example of what I would like to have with django-rest-framework (hand written):
{
"package_id": 20671,
"package": "jvim",
"mirrors": [
{
"name": "debian",
"components": [
{
"name": "main",
"releases": [
{
"name": "etch",
"version": "3.0-2.1b-1"
},
{
"name": "lenny",
"version": "3.0-2.1b-2.1"
},
{
"name": "sarge",
"version": "3.0-2.1a-5"
},
{
"name": "sid",
"version": "3.0-2.1b-3"
},
{
"name": "squeeze",
"version": "3.0-2.1b-3"
},
{
"name": "wheezy",
"version": "3.0-2.1b-3"
}
]
}
]
},
{
"name": "debian-amd64",
"components": [
{
"name": "main",
"releases": [
{
"name": "sarge",
"version": "3.0-2.1a-5"
}
]
}
]
},
{
"name": "debian-production",
"components": [
{
"name": "main",
"releases": [
{
"name": "etch",
"version": "3.0-2.1a-5"
},
{
"name": "etch-testing",
"version": "3.0-2.1a-5"
},
{
"name": "lenny",
"version": "3.0-2.1a-5"
},
{
"name": "lenny-testing",
"version": "3.0-2.1a-5"
},
{
"name": "sarge",
"version": "3.0-2.1a-5"
},
{
"name": "sarge-testing",
"version": "3.0-2.1a-5"
},
{
"name": "squeeze",
"version": "3.0-2.1a-5"
},
{
"name": "squeeze-testing",
"version": "3.0-2.1a-5"
},
{
"name": "wheezy",
"version": "3.0-2.1a-5"
},
{
"name": "wheezy-testing",
"version": "3.0-2.1a-5"
}
]
}
]
},
{
"name": "ubuntu",
"components": [
{
"name": "universe",
"releases": [
{
"name": "hardy",
"version": "3.0-2.1b-2.1"
},
{
"name": "lucid",
"version": "3.0-2.1b-3"
},
{
"name": "oneiric",
"version": "3.0-2.1b-3"
},
{
"name": "precise",
"version": "3.0-2.1b-3"
},
{
"name": "quantal",
"version": "3.0-2.1b-3"
},
{
"name": "raring",
"version": "3.0-2.1b-3"
}
]
}
]
},
{
"name": "ubuntu-production",
"components": [
{
"name": "universe",
"releases": [
{
"name": "hardy",
"version": "3.0-2.1b-2.1"
},
{
"name": "hardy-testing",
"version": "3.0-2.1b-2.1"
},
{
"name": "lucid",
"version": "3.0-2.1b-3"
},
{
"name": "lucid-testing",
"version": "3.0-2.1b-3"
},
{
"name": "precise",
"version": "3.0-2.1b-3"
},
{
"name": "precise-testing",
"version": "3.0-2.1b-3"
}
]
}
]
}
]
}

Answer myself...
Found a solution based on Django REST framework: non-model serializer
Maybe a better solution could be implemented?
class Pmcra(object):
package = None
package_id = None
def __init__(self, package, *args, **kw):
self.package = package
pass
def do_work(self):
my_dict = {}
if self.package:
pacmrs = Pacmr.objects.filter(package__name=self.package)
mirrors = pacmrs.all().distinct('mirror')
mirrors_array = []
for mirror in mirrors:
self.package_id = mirror.package.id
components = mirrors.filter(mirror=mirror.mirror).distinct('component')
components_array = []
for component in components:
releases = components.filter(component=component.component).distinct('release')
releases_array = []
for release in releases:
releases_array.append( {'name': release.release.__str__(), 'version': release.version.__str__() })
components_array.append( {'name': component.component.__str__(), 'releases': releases_array} )
mirrors_array.append( {'name': mirror.mirror.__str__(), 'components': components_array} )
return { 'package': self.package, 'package_id': self.package_id, 'mirrors': mirrors_array }
class MyView(APIView):
def get(self, request, *args, **kw):
# Process any get params that you may need
# If you don't need to process get params,
# you can skip this part
get_arg1 = request.GET.get('pkg', None)
# Any URL parameters get passed in **kw
myClass = Pmcra(get_arg1, *args, **kw)
result = myClass.do_work()
response = Response(result, status=status.HTTP_200_OK)
return response

Related

Check for values from list in a string from a measure

I have a Calculated column in table_1 which is a result of a measure that returns a string with several values in it. Each of these values represents a fault code and its format is DI followed by 4 digits.
Now I have a second table (table_2) that has a list of faults codes, some of those fault codes can be found in the string of the calculated column from the 1st table.
What I'm looking for is a measure that will return a 'True' statement if any row from the calculated column in the table1 has a fault code that is not on the list of fault codes from table2. Additionally will return a 'False' statement in case of all codes from the string of calculated column in table1 are present on the list of table_2. Please see a simplified example
.
The result should look as follow
.
So far I've managed to check if only the first value from the string in the calculated column of table 1 fulfils that condition. Unfortunately, I'm not able to apply it to the full string, Could someone support, please.
Table2 list
| List |
|--------|
| DI0001 |
| DI0002 |
| DI0003 |
| DI0004 |
| DI0005 |
| DI0006 |
| DI0007 |
| DI0008 |
| DI0009 |
| DI0011 |
| DI0013 |
| DI0015 |
| DI0105 |
| DI0107 |
| DI0108 |
| DI0211 |
| DI0212 |
| DI0505 |
| DI0806 |
| DI0907 |
| DI1113 |
| DI1212 |
| DI1504 |
| DI1505 |
| DI1601 |
| DI1602 |
| DI1603 |
| DI1604 |
| DI1605 |
| DI1606 |
| DI1607 |
| DI1608 |
| DI1609 |
| DI1610 |
| DI1611 |
| DI1612 |
| DI1613 |
| DI1614 |
| DI1615 |
| DI1616 |
| DI1617 |
| DI1618 |
| DI1701 |
| DI1702 |
| DI1703 |
| DI1704 |
| DI1705 |
| DI1706 |
| DI1707 |
| DI1708 |
| DI1801 |
| DI1802 |
| DI1803 |
| DI1804 |
| DI1901 |
| DI1902 |
| DI1903 |
| DI1904 |
| DI1905 |
| DI2601 |
| DI9901 |
| DI9902 |
| DI9903 |
| DI9904 |
| DI9905 |
| DI9906 |
| DI9907 |
| DI9908 |
| DI9909 |
| DI9910 |
| DI9911 |
| DI9912 |
| DI9913 |
Here is table1 and the calculated column
| Calculated Column |
|-----------------------------------------------------------|
| DI0501 DI1604 DI1605 |
| DI1604 DI1605 |
| DI1604 DI1605 |
| DI1605 |
| DI1604 DI1605 DI0105 |
| DI1604 DI1605 |
| DI0105 DI1604 DI1605 |
| DI1605 DI1604 |
| DI1604 DI1605 DI0105 DI1604 DI1604 DI1604 DI1604 DI1604 |
| DI1604 DI1605 |
| DI1605 |
| DI1604 DI1605 |
| DI1605 |
| DI1604 DI1605 DI0105 |
| DI0105 DI1604 DI1605 |
| DI1604 DI1605 |
| DI1010 DI1604 DI1605 DI0105 |
| DI1604 DI1605 DI0105 |
| DI1604 DI1605 DI1604 DI1604 DI1604 DI1604 DI1604 |
| DI1604 DI1605 |
| DI1604 DI1605 |
| DI1604 DI1605 DI0105 DI1604 DI1604 DI1604 DI1604 DI1604 |
| DI0204 |
| DI1015 DI0105 DI1604 DI1605 |
| DI1604 DI1605 DI0105 |
| DI1604 DI1605 DI0105 |
| DI1604 DI1605 DI0105 DI1604 DI1604 DI1604 DI1604 DI1604 |
| DI1102 DI1605 |
| DI1605 |
| DI1604 DI1604 DI1605 |
| DI1604 DI1605 DI1604 |
| DI1605 DI1604 DI1010 |
| DI0107 |
| DI0105 DI1604 DI1605 |
| DI1604 DI0204 |
| DI0105 DI1604 DI1605 |
| DI1605 |
| DI1604 DI1605 DI0105 DI1604 DI1604 DI1604 DI1604 DI1604 |
Example of a model in the link:
https://drive.google.com/drive/folders/1QVaPfMHkY_QQQmcUrBgTLNCDwmbuwq98?usp=sharing
This is the modified DAX Measure
_Measure =
VAR _1 =
FILTER (
ADDCOLUMNS (
Table_1,
"new", SUBSTITUTE ( Table_1[Calculated column], " ", "|" )
),
[new] <> BLANK ()
)
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _filt =
ADDCOLUMNS (
_2,
"score",
VAR _1 = [_txt]
VAR _2 =
CALCULATE ( MAX ( table_2[List] ), TREATAS ( { _1 }, table_2[List] ) )
RETURN
IF ( _2 = BLANK (), "x", _2 )
)
RETURN
IF (
COUNTX ( FILTER ( _filt, [score] = "x" ), [Calculated column] ) >= 1,
TRUE,
FALSE
)
If you are comfortable with Power Query, you can create a new table using this below Advanced Query code-
let
Source = Table_1,
#"Trimmed Text" = Table.TransformColumns(Source,{{"Calculated Column", Text.Trim, type text}}),
#"Sorted Rows" = Table.Sort(#"Trimmed Text",{{"Calculated Column", Order.Ascending}}),
#"Removed Other Columns" = Table.SelectColumns(#"Sorted Rows",{"Calculated Column"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
#"Added Index" = Table.AddIndexColumn(#"Removed Duplicates", "Index", 1, 1, Int64.Type),
#"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Calculated Column"}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Reordered Columns", {{"Calculated Column", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Calculated Column"),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Calculated Column", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Calculated Column"}, Table2, {"List "}, "Table2", JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"List "}, {"Table2.List "}),
#"Sorted Rows1" = Table.Sort(#"Expanded Table2",{{"Index", Order.Ascending}}),
#"Renamed Columns" = Table.RenameColumns(#"Sorted Rows1",{{"Table2.List ", "Table2.List"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"Index"}, {{"AllData", each _, type table [Index=number, Calculated Column=nullable text, #"Table2.List "=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [AllData][Calculated Column]),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
#"Added Custom1" = Table.AddColumn(#"Extracted Values", "Custom.1", each [AllData][Table2.List]),
#"Extracted Values1" = Table.TransformColumns(#"Added Custom1", {"Custom.1", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
#"Added Custom2" = Table.AddColumn(#"Extracted Values1", "Custom.2", each if Text.Length([Custom.1]) = 0 then false else true),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Index", "AllData", "Custom.1"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Calculated Column"}, {"Custom.2", "Is_present"}})
in
#"Renamed Columns1"
Output will be as below-
Now you can join your Table_1 and Table_1_new using Calculated Column and import Is_present from the new table for your further purpose.

How to match float value in mongoquery?

This is my sample documents collection of MongoDB. I need an expected result so anyone guide me to solve my problem
/* 1 */
{
"_id" : 1.0,
"user_id" : "5c592f6716209a24f4125001",
"tu_code" : "5"
}
/* 2 */
{
"_id" : 2.0,
"user_id" : "5c592f6716209a24f4125002",
"tu_code" : "50"
}
/* 3 */
{
"_id" : 3.0,
"user_id" : "5c592f6716209a24f4125003",
"tu_code" : "50.21"
}
/* 4 */
{
"_id" : 4.0,
"user_id" : "5c592f6716209a24f4125004",
"tu_code" : "50.22"
}
/* 5 */
{
"_id" : 5.0,
"user_id" : "5c592f6716209a24f4125005",
"tu_code" : "52"
}
/* 6 */
{
"_id" : 3.0,
"user_id" : "5c592f6716209a24f4125006",
"tu_code" : "5.1"
}
/* 7 */
{
"_id" : 6.0,
"user_id" : "5c592f6716209a24f4125007",
"tu_code" : "5.1.1"
}
/* 8 */
{
"_id" : 7.0,
"user_id" : "5c592f6716209a24f4125008",
"tu_code" : "5.2"
}
/* 9 */
{
"_id" : 8.0,
"user_id" : "5c592f6716209a24f4125009",
"tu_code" : "5.2.1"
}
Here I mentioned my mongo aggregate query below
[
{ "$project": {
"tu_code": { "$toLower": "$tu_code" },
}},
{ "$match": { "tu_code": {"$regex": "^5.*"}}}
]
This above query produces the below result
| _id| tu_code |
| ---| --------|
| 1 | 5 |
| 2 | 50 |
| 3 | 50.21 |
| 4 | 50.22 |
| 5 | 52 |
| 6 | 53 |
| 7 | 5.1 |
| 8 | 5.1.1 |
| 9 | 5.2 |
| 10 | 5.2.1 |
But I want expected result given below
| _id| tu_code |
| ---| --------|
| 1 | 5 |
| 7 | 5.1 |
| 8 | 5.1.1 |
| 9 | 5.2 |
| 10 | 5.2.1 |
Anyone help me to solve this I don't know how to get my expected result.
You can use the \b (word boundary) operator at the end of search expression,
[
{
"$match": {
"tu_code": {
"$regex": "^5\\b"
}
}
}
]
Playground

AppSync + DynamoDB: Query with filter doesn't return all valid items

I have Appsync API connecting to a Dynamo table.
Dynamo table has data : ("id" is key and "year" is sort key)
|--------------|-------------|-------------|-------------|-------------|
| id | year | name | class | subject |
|--------------|-------------|-------------|-------------|-------------|
| 001 | 2017 | Tom | E1 | Math |
|--------------|-------------|-------------|-------------|-------------|
| 002 | 2017 | Mary | E1 | Math |
|--------------|-------------|-------------|-------------|-------------|
| 003 | 2017 | Peter | E1 | Math |
|--------------|-------------|-------------|-------------|-------------|
the schema
type Query {
listStudents(filter: TableStudentFilterInput, limit: Int, nextToken: String): StudentConnection
}
type StudentConnection {
items: [Student]
nextToken: String
}
input TableStudentFilterInput {
id: TableStringFilterInput
year: TableStringFilterInput
name: TableStringFilterInput
class: TableStringFilterInput
subject: TableStringFilterInput
}
type Student {
id: String!
year: String!
name: String
class: String
subject: String
}
Query:
query listStudentByYear {
listStudents (filter:{year:{eq:"2017"}}) {
items {
id
year
name
class
subject
}
}
}
The issue: The query return 001 and 002, but not 003.
When I tried to update "id" from 003 to 004, then the query returns correctly 001, 002, 004.
This weird issue happens quite frequently, after some times, the AppSync query returns an incomplete result (missing some).
Any suggestion is appreciated.
Check out this thread from amplify-js issues.
Essentially what is happening is a limit is applied before the filter. So if you have a limit of 20 and 003 is entry number 21 it will not be included in the filter operation.
A workaround here is to remove the limit from you resolver in the AWS AppSync Console
So change this:
#set( $ListRequest = {
"version": "2017-02-28",
"limit": $limit
})
to this:
#set( $ListRequest = {
"version": "2017-02-28",
} )
Now this isn't a graceful workaround as the DynamoDB Scan will only return 1MB of data meaning this solution will not work for large (practical) implementations.

Is there a Power Bi Dax formula to show a result based on multiple conditions?

I have a Table which contains the following columns:
| Feature | Date | Update | hours|
|---------------------|------------------|-----------|------|
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |0 |
|PvP |2018-10-02 |V1 |3 |
|PvP |2018-10-02 |V1 |2 |
|PvP |2018-10-02 |V1 |1 |
|PvP |2018-10-02 |V1 |1 |
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |7 |
|General |2018-10-02 |V1 |0 |
|General |2018-10-02 |V1 |0 |
|Visual |2018-10-02 |V1 |7 |
|General |2018-10-15 |V1 |0 |
|General |2018-10-15 |V1 |0 |
|General |2018-10-15 |V1 |0 |
|Visual |2018-10-15 |V1 |7 |
|Visual |2018-10-15 |V1 |2 |
|General |2018-10-16 |V1 |1 |
Using this example i want to add a custom column that can count the number of runs executed for each feature based on the following criteria:
Calculate the sum of minutes based on feature for each day and:
For example if today's sum is higher than yesterday's, count as 1 run else count as zero.
Below is an example
| Feature | Date | Update | hours|No of runs|
|---------------------|------------------|-----------|------|----------|
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |0 |1
|PvP |2018-10-02 |V1 |3 |1
|PvP |2018-10-02 |V1 |2 |1
|PvP |2018-10-02 |V1 |1 |1
|PvP |2018-10-02 |V1 |1 |1
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |7 |1
|General |2018-10-02 |V1 |0 |1
|General |2018-10-02 |V1 |0 |1
|Visual |2018-10-02 |V1 |7 |1
|General |2018-10-15 |V1 |0 |0
|General |2018-10-15 |V1 |0 |0
|General |2018-10-15 |V1 |0 |0
|Visual |2018-10-15 |V1 |7 |1
|Visual |2018-10-15 |V1 |2 |1
|General |2018-10-16 |V1 |1 |1
The run counter should start from 1 for each feature.
So far i have tried to use the following formula but it gives incorrect information:
No_of_runs = CALCULATE(COUNTA('table'[Feature]),Filter('Table','Table'[Feature]=EARLIER('Table'[Feature]) && 'Table'[Date] > EARLIER('Table'[Date] && 'Table'[Time Invested(hours)] > Earlier('Table'[Time Invested(hours)])))
Not sure I've fully understood the logic, but try this as a calculated column:
No_of_runs =
VAR DateToday =
Table1[Date]
VAR MinutesToday =
CALCULATE (
SUM ( Table1[Time Invested (hours)] ),
FILTER (
ALLEXCEPT ( Table1, Table1[Feature] ),
Table1[Date] = DateToday
)
)
VAR MinutesYesterday =
CALCULATE (
SUM ( Table1[Time Invested (hours)] ),
FILTER (
ALLEXCEPT ( Table1, Table1[Feature] ),
Table1[Date] = DateToday - 1
)
)
RETURN
IF (
MinutesToday > MinutesYesterday,
1,
0
)
Edit: here's a worked example PBIX file; https://pwrbi.com/so_55588315/

VMware, Output the Network HealthCheck in on CSV file

I have a script, it work perfectly and everything is show on my power shell screen "Console". But I try to figure Out how to export in CSV
Script:
foreach($vds in Get-VDSwitch)
{
$vds.ExtensionData.Runtime.HostMemberRuntime | %{
$.HealthCheckResult | where{$ -is [VMware.Vim.VMwareDVSVlanHealthCheckResult]} |
Select #{N='vdSwitch';E={$vds.Name}},
UplinkPortKey,
#{N='TrunkedVLAN';E={
($.TrunkedVLAN | %{
if($.Start -eq $.End){
"{0}" -f $.Start
}
else{
"{0}-{1}" -f $.Start,$.End
}
}) -join ','
}}
}
}
The Output on screen look like this;
VsanEnabled : False
VsanDiskClaimMode : Manual
HATotalSlots : 3099
HAUsedSlots : 22
HAAvailableSlots : 1527
HASlotCpuMHz : 32
HASlotMemoryMb : 328
HASlotMemoryGB : 0.3203125
HASlotNumVCpus : 1
ParentId : Folder-group-h28
ParentFolder : host
HAEnabled : True
HAAdmissionControlEnabled : True
HAFailoverLevel : 1
HARestartPriority : Medium
HAIsolationResponse : DoNothing
VMSwapfilePolicy : WithVM
DrsEnabled : True
DrsMode : FullyAutomated
DrsAutomationLevel : FullyAutomated
EVCMode : intel-nehalem
Name : mac01dmzp01
CustomFields : {}
ExtensionData : VMware.Vim.ClusterComputeResource
Id : ClusterComputeResource-domain-c12033
Uid : /VIServer=cn\t175726#mac01vcp02.cn.ca:443/Cluster=ClusterComputeResource-domain-c12033/
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 78
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 79
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 82
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 83
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 358
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 359
TrunkedVLAN : 11-17,396,500
a lot more ......
I found the way to do it, is with a function.
#####################################################
# vSphere 6.5
# Get ESX HealthCheck Network Config from VDS
#
# by Gerald Begin (Nov.20 2018)
#################################
##### Set Script Location
Set-Location T:\___Main-Script___\_VDS-vLANs_
##### Add VMWare Module.
Get-Module -Name VMware* -ListAvailable | Import-Module
##### Output Path
$Desti = 'T:\___Main-Script___\_VDS-vLANs_\Output'
Import-Module -Name "T:\__Script_Functions__\Connect2All.ps1" -Force:$true # Function to Connect to ALL vCenters
$Clster = "mac01dmzp01"
#### --------------------------------------
function GetInfo {
###################################################
foreach($vds in Get-VDSwitch)
{
$vds.ExtensionData.Runtime.HostMemberRuntime | %{
$_.HealthCheckResult | where{$_ -is [VMware.Vim.VMwareDVSVlanHealthCheckResult]} |
Select #{N='vdSwitch';E={$vds.Name}},
UplinkPortKey,
#{N='TrunkedVLAN';E={
($_.TrunkedVLAN | %{
if($_.Start -eq $_.End){
"{0}" -f $_.Start
}
else{
"{0}-{1}" -f $_.Start,$_.End
}
}) -join ','
}}
}
}
}
Get-Cluster -Name $Clster | GetInfo | Export-Csv -Path $Desti\Results.csv -NoTypeInformation
Disconnect-VIServer * -Confirm:$false